PHP inheritance question, freaking me out
Got a question that is freaking me out. Do parent constructors constructs it开发者_开发问答self without being called?
Cause Im seeing it working on a situation and not on the script Im writing.
I got the following:
boot.php
$this->router = new router($param);
router.php
class router extends routerController
- on the class router I don't have any __construct.
routercontroller.php
class routerController{
function __construct($param){
$this->param = $param;
}
- if I add a __construct to the class router the __construct from the extended class routerController is not executed. So, it seems on this case the constructor is being constructed without a parent::_construct.
On the same script I got inside the routerController class.
$this->newclass = newclass($this->param);
newClass extends someClass. For some reason the someClass constructor is not instantiated if I don't call it from the newClass using parent::__construct($param).
I already spent hours reviewing all the code and can't find what Im doing wrong. Why in the first case the parent constructor is instantiated without being called and on the second case not?
Is this a bug? Any idea what I am doing wrong?
In PHP parent constructors aren't called implicitly.
Source: http://php.net/manual/en/language.oop5.decon.php
精彩评论