8.18. Dereferencing Object Return ValuesIf you call a function that returns an object, you can treat the return value of that function as an object from the calling line and access it directly. For example: $lassie = new Dog( ); $collar = $lassie->getCollar( ); echo $collar->Name; $poppy = new Dog( ); echo $poppy->getCollar( )->Name; In the first example, we need to call getCollar( ) and save the returned value into $collar, before echoing out the Name property of $collar. In the second example, we use the return value from getCollar( ) immediately from within the same line of code, and echo out Name without an intermediate property like $collar.
|