binarymonkey Posted November 23, 2007 Share Posted November 23, 2007 Hi, Quick question, I am trying to do the following: <?php class SubObject { var $someVar = 'bar'; } class MainObject { var $oSubObject; var $someVar='foo'; function __construst() { $this->oSubObject = new SubObject(); } } $oMainObject = new MainObject(); # works $refString = 'someVar'; echo($oMainObject->{$refString}); #outputs 'foo' # does not work $refString = 'oSubObject->someVar'; echo($oMainObject->{$refString}); # fails (expected output 'bar') ?> Where I am trying to get the sub object variable, I get the following E_NOTICE error: Notice: Undefined property: MainObject::$oSubObject->someVar in test.php Any ideas? Matthew Link to comment https://forums.phpfreaks.com/topic/78543-referencing-sub-subjects-and-variables-with-a-variable/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.