#31669 [Opn->Bgs]: no __construct() method in parent causes error...
| From: | helly@php.net | Date: | Sun, 23 Jan 2005 19:32:30 +0000 |
| Subject: | #31669 [Opn->Bgs]: no __construct() method in parent causes error... | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-72704@lists.php.net to get a copy of this message | ||
ID: 31669
Updated by: helly@php.net
Reported By: jason at amp-design dot net
-Status: Open
+Status: Bogus
Bug Type: Zend Engine 2 problem
-Operating System: CentOS / Mac OS X
+Operating System: *
-PHP Version: 5.0.3
+PHP Version: 5.*
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
It is 'a language level issue' by design.
Previous Comments:
------------------------------------------------------------------------
[2005-01-23 16:06:38] jason at amp-design dot net
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 this bug report at http://bugs.php.net/?id=31669&edit=1