|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-10-07 09:20 UTC] dagguh at gmail dot com
Description:
------------
You cannot call default constructor from derived class.
Test script:
---------------
<?
class Base {
}
class Derived extends Base {
function __construct($foo) {
parent::__construct();
echo $foo;
}
}
$derived = new Derived("baz");
Expected result:
----------------
baz
Actual result:
--------------
Fatal error: Cannot call constructor
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 22:00:01 2025 UTC |
I stand by my request because of cohesion. I often see useless code in derived classes, e.g.: function __construct($name) { parent::__construct($name); } which does absolutely nothing and I delete this code, because php will do it automatically. For the same reason I'd like to remove function __construct() { ; } which also does absolutely nothing and php will do the same automatically EXCEPT in the case I described. So, I stand by my request :)