Domcsore Posted March 23, 2010 Share Posted March 23, 2010 Hey there, I have 3 files. my index.php global_reg.php template.config.php this is what i have: index.php - <?php include_once('classes/global_reg.php'); $global_conf = new globalconf; /** LOAD ENGINES **/ $global_conf->engineload("template.conf.php"); $global_conf->echome(); ?> Then global_reg.php (I wont display it all) - <?php class globalconf{ /** DEFINE VARIABLES **/ public $loadengine; public function engineload($classfile){ $this->loadengine = array( "class"=>"classes/subclasses/" ); include_once($this->loadengine['class'].$classfile); } } ?> and template.config.php <?php class template extends globalconf{ public function echome(){ echo "Me"; } } ?> but im getting the error: Fatal error: Call to undefined method globalconf::echome() in index.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/196273-class-extend-trouble/ Share on other sites More sharing options...
KevinM1 Posted March 23, 2010 Share Posted March 23, 2010 I don't think you're looking at extend in the right way. It doesn't extend your current class. It specifies that one class (template) is the child of a parent class (globalconf). Your parent class doesn't have access to members defined in the child. So globalconf doesn't magically get the echome method you define in template. Quote Link to comment https://forums.phpfreaks.com/topic/196273-class-extend-trouble/#findComment-1030722 Share on other sites More sharing options...
schilly Posted March 23, 2010 Share Posted March 23, 2010 my OOP isn't great but I believe you need to create a template object in order to call echome. you can't just include it in your engineload. plus inheritance only goes the other way. i don't think a globalconf object could call a template function unless you casted it? where as a template object would inherit all the globalconf member functions because it extends globalconf. Quote Link to comment https://forums.phpfreaks.com/topic/196273-class-extend-trouble/#findComment-1030723 Share on other sites More sharing options...
o3d Posted March 23, 2010 Share Posted March 23, 2010 I think $global_conf = new globalconf; should be $global_conf = new template; You are creating an instance of template (which extends from globalconf). Thus by having an instance of template, you should have access to globalconf's public methods and properties. Quote Link to comment https://forums.phpfreaks.com/topic/196273-class-extend-trouble/#findComment-1030798 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.