OO understanding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

OO understanding

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: OO understanding

Post 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...
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

I wanted to learn OO php form where i can get help, i wanted to start with basic and move on.

thanks
Post Reply