Jump to content

[SOLVED] O.O.P. echo/print question...


suttercain

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

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.