Bug #52687 [Opn->Wfx]: parent::__construct in extended classes - not downward compatible change
| From: | cmb@php.net | Date: | Fri, 12 Aug 2016 18:33:40 +0000 |
| Subject: | Bug #52687 [Opn->Wfx]: parent::__construct in extended classes - not downward compatible change | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-203222@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=52687&edit=1
ID: 52687
Updated by: cmb@php.net
Reported by: alex dot aulbach at mayflower dot de
Summary: parent::__construct in extended classes - not
downward compatible change
-Status: Open
+Status: Wont fix
Type: Bug
Package: Scripting Engine problem
Operating System: linux
PHP Version: 5.3.3
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Confirmed: <https://3v4l.org/Y2KOX>.
Anyhow, changing the behavior *now* wouldn't make any sense, as
the PHP 4 style constructors have been deprecated as of PHP 7.0.0.
> If you want to discuss this (of course not here), you might also
> tell me where - I would like to join.
If you're still interested, just email to internals at lists dot
php dot net.
Previous Comments:
------------------------------------------------------------------------
[2010-08-24 13:45:29] alex dot aulbach at mayflower dot de
Description:
------------
See the code. When running under 5.2.8 this works. Running under 5.3.2 it does not. (The
error-message is in comments, line 22 is "parent::class2();")
We have old code like this, because we have a big, old project and many changes. So it might have
happened, that the constructor at level 2 was removed.
To this bug:
-------------
I think it was introduced with fixing this bug:
http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/Zend/zend_API.c?r1=288088&r2=291488&pathrev=291491
I found also other bugs, which describe some other misbehaviour of __construct():
http://bugs.php.net/bug.php?id=52120
http://bugs.php.net/bug.php?id=49203
My opinion :
--------------
Before you just fix it, I want to discuss this bug, because I think, that the old-constructor style
of PHP should be removed in long terms (3 years or so, I don't know the current discussion
about this).
So, instead of fixing those bugs with lots of code, which introduces new bugs (and let people think,
that PHP is buggy or the developers are too lazy :) ), it might be better *not to fix* it (!), make
good documentations around this and create a tool, which scans PHP-code for those "bugs"
or better "old stylish code" which - depending on difficulty - also suggest how to repair
it.
My reason for that is, that there will be many other incompatibility changes in the future (and was
in the past) and we never can make PHP so downward compatible that it will work without problems on
7 years old code - no matter how nice the code originally was written.
To be pro-active, I begun to write such a tool (in PHP of course) and it currently finds classes
which have the old constructor-method inside (name of class = name of method). I'm willing to
develop this further.
If you are interested going this way just tell here. If you want to discuss this (of course not
here), you might also tell me where - I would like to join.
Test script:
---------------
<?php
class class1 {
function class1() {
error_log("Constuctor of class1");
}
}
class class2 extends class1 {
}
class class3 extends class2 {
}
class class4_working extends class3 {
function class4_working() {
parent::__construct();
}
}
class class4_notworking extends class3 {
function class4_notworking() {
parent::class2();
}
}
error_log("working");
$c = new class4_working();
error_log("notworking");
$c = new class4_notworking();
//PHP Fatal error: Call to undefined method class3::class2() in /.../classconstructtest.php on line
22
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=52687&edit=1