ShibSta Posted September 21, 2010 Share Posted September 21, 2010 I've been coding PHP for some time and would consider myself to be at an intermediate level. I can write code to do what I need but it's probably not the best way to do it. I rarely see any code that I am not able to read, understand, or follow. I've created modifications for everything from vBulletin, WordPress, Kayako Support Suit, Magento, and more. However, I've never really built a strong understanding around OOP. For example, let say you have the following classes: _main - db - admin - - modules - - - dashboard How would you share the db connection with the dashboard class? I've been trying to read up on Dependency Injections and Singletons but I haven't found an article that has explained it on a level that I can understand. I get a feeling that most people who use OOP in PHP have a background in Java or C++ and are much more familiar with everything. Could someone please explain this to me in simple terms or link me to an extremely well explained article that I'd be able to understand without a background in computer science? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/213962-questions-about-oop/ Share on other sites More sharing options...
ignace Posted September 21, 2010 Share Posted September 21, 2010 How would you share the db connection with the dashboard class? Pretty much like you would share anything else: by passing it through the constructor or a setter-method. public function setDatabaseAdapter(Zend_Db_Adapter_Abstract $adapter) Quote Link to comment https://forums.phpfreaks.com/topic/213962-questions-about-oop/#findComment-1113587 Share on other sites More sharing options...
chintansshah Posted September 21, 2010 Share Posted September 21, 2010 I think, best way to know about OOP in PHP from php.net website. Please find the link http://php.net/manual/en/language.oop5.php Quote Link to comment https://forums.phpfreaks.com/topic/213962-questions-about-oop/#findComment-1113593 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.