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 Quote Link to comment 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.