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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

object->method1()->method2 ???

Status
Not open for further replies.

Kareem

Programmer
Nov 11, 2002
13
CH
Hi

Could anybody tell me how I can use an objects method if I got the object as a result of another method?

Example:

Instead of doing
$obj=object->getAnotherObject();
$obj->methodX();

I want to do $object->getAnotherObject()->methodX();

While I'm using this all the time in Java I can't get it working this way with PHP?

Any help would be apreciated.

Thanks
 
Are you using PHP 4? If so, you're just out of luck, because it doesn't support method chaining. Sorry.

However, if you use PHP 5, then the example you posted should work perfectly.
 
Thank you!

Well I guess it's definitly time to switch to PHP 5...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top