parino_esquilado Posted January 24, 2011 Share Posted January 24, 2011 Take the following example: <?php class a { var $things; public function __construct($stuff) { $this->things = $stuff; } } class b { var $morethings; $this->morethings = "something"; } $c = new a(new b); echo $c->things->__PARENT__; ?> The line "echo $c->things->__PARENT__;" (as you can probably imagine) does not work. How would I output what the 'b' object is stored in ('a')? Link to comment https://forums.phpfreaks.com/topic/225476-classes-help/ Share on other sites More sharing options...
trq Posted January 24, 2011 Share Posted January 24, 2011 echo $c->things->morethings; As a side note, a & b are in no way related. Link to comment https://forums.phpfreaks.com/topic/225476-classes-help/#findComment-1164307 Share on other sites More sharing options...
parino_esquilado Posted January 24, 2011 Author Share Posted January 24, 2011 <?php class a { var $things; public function __construct($stuff) { $this->things = new b; } } class b { var $morethings; $this->morethings = "something"; } $c = new a(); echo $c->things->__PARENT__; ?> Are a and b related now? Link to comment https://forums.phpfreaks.com/topic/225476-classes-help/#findComment-1164351 Share on other sites More sharing options...
trq Posted January 24, 2011 Share Posted January 24, 2011 No. a just depends on b. See http://php.net/manual/en/language.oop5.inheritance.php Link to comment https://forums.phpfreaks.com/topic/225476-classes-help/#findComment-1164722 Share on other sites More sharing options...
parino_esquilado Posted January 25, 2011 Author Share Posted January 25, 2011 thanks. =) Link to comment https://forums.phpfreaks.com/topic/225476-classes-help/#findComment-1164894 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.