ryanlball@gmail.com Posted November 24, 2009 Share Posted November 24, 2009 Hello! In trying to understand Zend Framework a little better I've been going through some of the core library code. I've been tracing the general path from Zend_Application. I've noticed several times that a method simply returns 'return $this'. I've never seen that before. It's really cool and I'm excited to understand what it means. Below is one example: found in Zend_Loader_Autoloader public function setAutoloaders(array $autoloaders) { $this->_autoloaders = $autoloaders; return $this; } I really appreciate this help! Quote Link to comment https://forums.phpfreaks.com/topic/182815-return-this-what-is-it-returning/ Share on other sites More sharing options...
Mchl Posted November 24, 2009 Share Posted November 24, 2009 http://www.php.net/manual/en/language.oop5.basic.php Quote Link to comment https://forums.phpfreaks.com/topic/182815-return-this-what-is-it-returning/#findComment-964889 Share on other sites More sharing options...
ryanlball@gmail.com Posted November 24, 2009 Author Share Posted November 24, 2009 Thank you for the answer. I understand using $this->whatever or $this->whatever($blah) but the difficulty I'm having is that there is nothing after the word '$this'. It's not pointing to anything. Quote Link to comment https://forums.phpfreaks.com/topic/182815-return-this-what-is-it-returning/#findComment-964904 Share on other sites More sharing options...
Mchl Posted November 24, 2009 Share Posted November 24, 2009 It returns the object itself. See this example: <?php class example { public function returnSelf() { return $this; } } $var1 = new example(); $var2 = $var1->returnSelf(); var_dump($var1); var_dump($var2); Quote Link to comment https://forums.phpfreaks.com/topic/182815-return-this-what-is-it-returning/#findComment-964933 Share on other sites More sharing options...
ryanlball@gmail.com Posted November 24, 2009 Author Share Posted November 24, 2009 Oh, I see. That makes sense. So, in a sense, when I create an object $obj = new Class() that object is being returned in a similar way as 'return $this;'. Thank you, again for your response. That's very kind. Quote Link to comment https://forums.phpfreaks.com/topic/182815-return-this-what-is-it-returning/#findComment-964980 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.