Jump to content

Recommended Posts

Hi guys,

 

I am trying to learn PHP and am doing a tutorial:

 

<?php
   class dogtag {
   public $Words;
	}

class dog {
   public $Name;
   public $DogTag;

   public function bark() {
      print "Woof!\n";
   		}
}

   class poodle extends dog {
      public function bark() {
         print "{$this->Name} says Woof!\n";
      } 
  
  public function whimper() {
  	print "Sniffle, Sniffle.\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";
print "$poppy->Name";
print "<br>";
print "$poppy->DogTag->Words";
?>

 

When I run the above code I get the following error:

Poppy

Catchable fatal error: Object of class dogtag could not be converted to string in C:\wamp\www\ARB\medialib\php_info.php on line 32[/b]

 

What would be the correct way to echo or print:

$poppy->DogTag->Words

 

Thanks for the help.

Link to comment
https://forums.phpfreaks.com/topic/51883-solved-oop-echoprint-question/
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.