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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.