suttercain Posted May 17, 2007 Share Posted May 17, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/51883-solved-oop-echoprint-question/ Share on other sites More sharing options...
suttercain Posted May 17, 2007 Author Share Posted May 17, 2007 Got it. Quote Link to comment https://forums.phpfreaks.com/topic/51883-solved-oop-echoprint-question/#findComment-255724 Share on other sites More sharing options...
redbullmarky Posted May 17, 2007 Share Posted May 17, 2007 Got it. care to share? Quote Link to comment https://forums.phpfreaks.com/topic/51883-solved-oop-echoprint-question/#findComment-255796 Share on other sites More sharing options...
suttercain Posted May 17, 2007 Author Share Posted May 17, 2007 Got it. care to share? Sure thing... I took off the double quotes and instead did: print $poppy->DogTag->Words; That worked. Quote Link to comment https://forums.phpfreaks.com/topic/51883-solved-oop-echoprint-question/#findComment-255909 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.