x1nick Posted May 26, 2010 Share Posted May 26, 2010 Don't quite know where I got this idea from but wondering if im going along the wrong lines of thinking. Basically I have a main class called `cms` where all my main functions are held for including files etc Now within my other class, for example `mysql` I want to be able to access the data set within cms->cfg Now what is the best way to do this without using global $cms, thorugh class mysql extend cms May work but that dosent class cms { var $cfg = array(); function addcfg($key,$value) { $cfg[$key] = $value; } } $cms = new cms(); mysql: class mysql extend cms { function connect() { $user = $this->cfg['username']; #do my sql connect.. } } $db = new mysql(); So basically how can I get access to the cms class within mysql without using global. Quote Link to comment https://forums.phpfreaks.com/topic/202991-using-mutiple-classes-question/ Share on other sites More sharing options...
Mchl Posted May 26, 2010 Share Posted May 26, 2010 http://en.wikipedia.org/wiki/Object_composition Quote Link to comment https://forums.phpfreaks.com/topic/202991-using-mutiple-classes-question/#findComment-1063737 Share on other sites More sharing options...
ignace Posted May 26, 2010 Share Posted May 26, 2010 In case you don't understand what Mchl wants to say or you don't understand the article, he meant: class CMS { private $mysql = null; public function initMySQL() { $this->mysql = .. } } favor composition over inheritance Quote Link to comment https://forums.phpfreaks.com/topic/202991-using-mutiple-classes-question/#findComment-1063804 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.