Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referring to one object from within a method of anotherobject

Status
Not open for further replies.

roardood

Technical User
Apr 11, 2002
11
ZA
I have a script where I have two objects of two different classes, call them Object A and Object B. Object A has a method called Method_A and Object B has a method called Method_B.

When I initialise Object B, I pass a reference to Object A and assign it to $Object_A. So far so good.However, now I have reached a situation where I wish to call Method_A of Object A from within Method_B of Object B. This would result in code that looks something like this :

/*Code starts here*/

function Method_B ()
{

$arbitrary_variable = $this->Object_A->Method_A();

}

/*Code ends Here*/

My question now is: Will the code above work or will PHP tell me to &*^% off?

Regards

Roardood

 
Nope. Being lazy I guess, was just hoping that it would take less time to get an answer than to knock together a test case, but ( insert dramatic_sigh_of_overworked _and_underpaid_person.wav here) I guess it looks like the latter course is becoming necessary.

R
 
OK..tried it and the code I was asking about in my original post does work...only took me about five minutes to dummy up....laziness never prospers.

R
 
I did not expect it to, but I was not sure.

The ability to perform chained object references (object->object->method) is problematic in PHP 4.x. The ability to do what you want to do will be implemented in PHP 5.x, due out this summer. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top