Section 8.6. Objects Within Objects


8.6. Objects Within Objects

You can use objects inside other objects in the same way as other variable types. For example, we could define a DogTag class and give each Dog a DogTag object like this:

     class DogTag {             public $Words;     }     class Dog {             public $Name;             public $DogTag;             public function bark( ) {                     print "Woof!\n";             }     }     // definition of Poodle... 

Accessing objects within objects is as simple as using -> again:

     $poppy = new Poodle;     $poppy->Name = "Poppy";     $poppy->DogTag = new DogTag;     $poppy->DogTag->Words = "My name is Poppy. If you find me, please call 555-     1234"; 

The $DogTag property is declared like any other, but needs to be created with new once $poppy has been created.



PHP in a Nutshell
Ubuntu Unleashed
ISBN: 596100671
EAN: 2147483647
Year: 2003
Pages: 249

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net