php - Class doesn't inherit - class not found -
i have troubles inheritance. have that
file a.php
namespace main; class a{ public function __construct(){ echo 'a->__construct'; } }
and file b.php
namespace main; class b extends \main\a{ /* if write construct , remove extends class - works - need inherit */ public function __construct(){ $a = new \main\a(); } public function something(){ echo 'b->something';} }
are there cases when classes cannot inherited or inherit class?
i had similar problem driving me crazy.
as test, copied parent class, renamed (i.e. code of abstract class same apart file name , class names) , inherit problem 'fixed'. weird!.
in case found class had require_once class causing error (i.e. 'b' in original poster's example) , removing (e.g.) 'require_once b' fixed it. somehow must have introduced circular causing php not load class - have no idea why, if has ideas, i'd love increase knowledge.
anyway... have moved on using spl_autoload_register (definitely way go). using spl_autoload_register in conjunction removing require_once whenever find 1 seems have solved problem.
i know reply late original poster, hope helps else pulling hair out (like was) similar issue.
Comments
Post a Comment