Page 1 of 1

OO understanding

Posted: Wed Jun 28, 2006 8:26 am
by itsmani1
Assuming all classes has been included here is some code.

I am new to OO code, can any one help me in understanding following line:

Code: Select all

$objProd->m_objCat = new clsCategory(); //m_objCat defined in clsProducts
$objProd->m_objCat->m_intCatId = $_REQUEST['catid'];
$objCat->m_intCatId=$_REQUEST['catid'];
$strTitleCatName = $objCat->GetCatName();
here is complete code.

Code: Select all

$objProd = new clsProducts();
$objProd->m_objCat = new clsCategory();

$objCat = new clsCategory();

if(isset($_REQUEST['catid']))
{
	$objProd->m_objCat->m_intCatId = $_REQUEST['catid'];
	$objCat->m_intCatId=$_REQUEST['catid'];
	$strTitleCatName = $objCat->GetCatName();
}
thanks

Re: OO understanding

Posted: Wed Jun 28, 2006 8:53 am
by timvw
itsmani1 wrote:

Code: Select all

$objProd->m_objCat = new clsCategory(); //m_objCat defined in clsProducts
$objProd->m_objCat->m_intCatId = $_REQUEST['catid'];
$objCat->m_intCatId=$_REQUEST['catid'];
$strTitleCatName = $objCat->GetCatName();
The first three aligns are assignments...

The first one assigns a new instance of clsCategory to $objProd->m_objCat..
The second assigns the value of $_REQUEST['catid'] to $objProd->m_objCat->m_intCatId...

Perhaps this double indirection confuses you... The following code does the same:

Code: Select all

$cls = new clsCategory();
$cls->m_intCatId = $_REQUEST['catid'];
$objProd->m_objCat = $cls;
And the last line assigns the returned value fromt he $objCat->GetCatName() method to the $strtitleCatName variable...

Posted: Sat Aug 12, 2006 2:58 am
by itsmani1
I wanted to learn OO php form where i can get help, i wanted to start with basic and move on.

thanks