Jump to content

Objects within Objects question


silverglade

Recommended Posts

Hi, I have some code I am a little confused about. If anyone can help me I'd appreciate it. Below is the code and I have commented my question within the code. Thanks.

 

class DogTag {

                  public  $Words;

           }

           class Dog {
                             public $Name;
                             public $DogTag;// I don't know what this variable is for it looks like we never use it.
                                                         //since we make the new DogTag object below from the class, what 
                                                           // do we need the $DogTag variable for please?
                             public function bark() {
                                 print "Woof!\n";
                              }
                            }

           $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";
                    

Link to comment
https://forums.phpfreaks.com/topic/240052-objects-within-objects-question/
Share on other sites

The code is very simple:

 

$poppy->DogTag = new DogTag;

 

This is creating a "DogTag" object and assigning it to $poppy->DogTag.

 

So clearly the DogTag variable in the Dog object IS being used, so store an associated DogTag object.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.