The Little Guy Posted May 5, 2011 Share Posted May 5, 2011 I can not understand why this isn't working, basically it works in one place but not the other I have this in my main class: class phpLive{ public function loadCore(){ foreach(glob($this->location."/core/*/*.core.php") as $coreFile){ $info = (object)pathinfo($coreFile); require_once $coreFile; $pos = strrpos($info->dirname, "/"); $coreMedia = substr($info->dirname, $pos + 1); $className = str_replace(".core", "", $info->filename); $instance = strtolower($className); $this->$coreMedia->$instance = new $className(); } } } On the page that I run (index.php), I use this: $_live->example->loadurl(); which is in a class that looks like this: <?php class ExampleClass extends phpLive{ public function __construct(){ $this->loadCore(); } public function loadurl(){ $this->net->http->getHttp('http://google.com'); } } ?> and I get the following error: Notice: Undefined property: ExampleClass::$net in C:\wamp\www\phpLive\phpLive\plugins\Example\ExampleClass.inc.php on line 7 Notice: Trying to get property of non-object in C:\wamp\www\phpLive\phpLive\plugins\Example\ExampleClass.inc.php on line 7 Fatal error: Call to a member function getHttp() on a non-object in C:\wamp\www\phpLive\phpLive\plugins\Example\ExampleClass.inc.php on line 7 but, when I run this on the main page: $_live->net->http->getHttp("http://google.com"); The code works just fine. Why doesn't the first one work (the above is the actual code, copy and pasted from my editor)? Quote Link to comment https://forums.phpfreaks.com/topic/235636-object-works-in-indexphp-but-not-in-the-extended-class/ Share on other sites More sharing options...
The Little Guy Posted May 5, 2011 Author Share Posted May 5, 2011 I got it! <?php class ExampleClass extends phpLive{ public function __construct(){ parent::__construct(); } public function loadurl(){ $this->net->http->getHttp('http://google.com'); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235636-object-works-in-indexphp-but-not-in-the-extended-class/#findComment-1211122 Share on other sites More sharing options...
spiderwell Posted May 5, 2011 Share Posted May 5, 2011 i experienced the very same problem last week Quote Link to comment https://forums.phpfreaks.com/topic/235636-object-works-in-indexphp-but-not-in-the-extended-class/#findComment-1211129 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.