#31669 [NEW]: no __construct() method in parent causes error...

From: Date: Sun, 23 Jan 2005 15:06:40 +0000
Subject: #31669 [NEW]: no __construct() method in parent causes error...
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-72696@lists.php.net to get a copy of this message
From: jason at amp-design dot net Operating system: CentOS / Mac OS X PHP version: 5.0.3 PHP Bug Type: Zend Engine 2 problem Bug description: no __construct() method in parent causes error... Description: ------------ If you extend from a base class with no explict constructor defined, and the derived class has a call to parent::__construct(), an error is raised. However it is perfectly legit to call new Dummy(), despite the fact Dummy has no explict constructor. Surely, if no constructor is defined in a base class, it should provide a default null/empty constructor to prevent errors. Without this, programmers have to provide a empty __construct method, which seems be silly as it serves no purpose other than to act as 'scaffolding code'. I have checked in the PHP Manual under the OO bit for PHP4 and PHP5 to make sure this is not the intended behaviour for PHP. If this is not a bug and you have to provide dummy constructors, this should be made clear in the documentation. If needed I can test this at home under Windows as well using a CVS snapshot if I get time. I'm sure it will produce the same result as it appears to be a language level issue. Reproduce code: --------------- <?php class Dummy { // uncomment here to make me work :-) // function __construct() {} } class BillGates extends Dummy { function __construct() { parent::__construct(); } } $new_idiot_to_dominate_world = new BillGates(); ?> Expected result: ---------------- Nothing should be output. $new_idiot_to_dominate_world should have an instance of BillGates. Actual result: -------------- Fatal error: Can not call constructor in BillGatesIsAScumBag.php on line 10 -- Edit bug report at http://bugs.php.net/?id=31669&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31669&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31669&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31669&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=31669&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=31669&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=31669&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=31669&r=needscript Try newer version: http://bugs.php.net/fix.php?id=31669&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=31669&r=support Expected behavior: http://bugs.php.net/fix.php?id=31669&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=31669&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=31669&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=31669&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31669&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=31669&r=dst IIS Stability: http://bugs.php.net/fix.php?id=31669&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=31669&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=31669&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=31669&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=31669&r=mysqlcfg

« previous php.bugs (#72696) next »