johnwarde Posted April 18, 2007 Share Posted April 18, 2007 Hi, I am trying to use an object reference directly from a function call (that returns the object reference): echo $objTestB->getObj()->getVal(); See code for full example. class TestA { var $_strTest = 'Hello World!'; function getVal() { return $this->_strTest; } } class TestB { var $_objTestA = NULL; function TestB() { $this->_objTestA = new TestA; } function &getObj() { return $this->_objTestA; } } $objTestB = new TestB; $refTestA = $objTestB->getObj(); echo $refTestA->getVal(); // I know the above 2 lines work, but I want to do it in one line like this... echo $objTestB->getObj()->getVal(); Thanks for your help, JB Quote Link to comment https://forums.phpfreaks.com/topic/47567-using-an-oject-reference-directly-return-from-a-function-call/ Share on other sites More sharing options...
per1os Posted April 18, 2007 Share Posted April 18, 2007 I do not think that is possible with PHP. I know it is in like VB .NET and other language but I have yet to figure it out in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/47567-using-an-oject-reference-directly-return-from-a-function-call/#findComment-232217 Share on other sites More sharing options...
Zane Posted April 18, 2007 Share Posted April 18, 2007 have you tried it yet? try it and you'll know if it works or not Quote Link to comment https://forums.phpfreaks.com/topic/47567-using-an-oject-reference-directly-return-from-a-function-call/#findComment-232268 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.