Ravani Posted February 2, 2011 Share Posted February 2, 2011 Hi everyone, I was discussing this topic with one of my friends and both of us can't give a real answer to this. Example: class test { function a(){ $obj = new DB_TableObject(); //blabla bla $this->b($obj); } function b($object){ $object->getResults(); } } class test { function a(){ $obj = new DB_TableObject(); //blabla bla $this->b($obj); } function b(){ $obj = new DB_TableObject(); $object->getResults(); } } Which one is better? The first or the second solution? Quote Link to comment https://forums.phpfreaks.com/topic/226458-speed-issue/ Share on other sites More sharing options...
jamesxg1 Posted February 2, 2011 Share Posted February 2, 2011 Is something like this better for you? <?php class test { public function __construct() { $this->object = new DB_TableObject(); } public function returnResults() { $this->object->getResults(); } } ?> James. Quote Link to comment https://forums.phpfreaks.com/topic/226458-speed-issue/#findComment-1168874 Share on other sites More sharing options...
ManiacDan Posted February 2, 2011 Share Posted February 2, 2011 James is right. You can also look into instances singleton classes, so you can just say DB_Object::getInstance() every time, which always returns the same memory location. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/226458-speed-issue/#findComment-1168891 Share on other sites More sharing options...
Ravani Posted February 2, 2011 Author Share Posted February 2, 2011 Thanks a constructor would be a good solution indeed, however it seems that the Zend Framework has trouble with that. So using DB_Object::getInstance() will be a good solution as well? Quote Link to comment https://forums.phpfreaks.com/topic/226458-speed-issue/#findComment-1168903 Share on other sites More sharing options...
ManiacDan Posted February 2, 2011 Share Posted February 2, 2011 Zend framework doesn't have a problem with constructors, they're critical to OOP development. What makes you think it has a problem? Quote Link to comment https://forums.phpfreaks.com/topic/226458-speed-issue/#findComment-1168907 Share on other sites More sharing options...
jamesxg1 Posted February 2, 2011 Share Posted February 2, 2011 Dan's right here Ravani, Zend has no issue with constructors. When it comes to OOP programming constructors are essential. James. Quote Link to comment https://forums.phpfreaks.com/topic/226458-speed-issue/#findComment-1168917 Share on other sites More sharing options...
Ravani Posted February 2, 2011 Author Share Posted February 2, 2011 You're right, however I'm getting this error: Fatal error: Declaration of LoginController::__construct() must be compatible with that of Zend_Controller_Action_Interface::__construct() in Seems like I need to add some arguments in the constructor but I don't really know which one. Quote Link to comment https://forums.phpfreaks.com/topic/226458-speed-issue/#findComment-1168954 Share on other sites More sharing options...
ManiacDan Posted February 2, 2011 Share Posted February 2, 2011 Whichever ones are in the Zend_Controller_Action_interface constructor. Look into inheritance in OOP PHP. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/226458-speed-issue/#findComment-1169018 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.