php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52687 parent::__construct in extended classes - not downward compatible change
Submitted: 2010-08-24 13:45 UTC Modified: 2016-08-12 18:33 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: alex dot aulbach at mayflower dot de Assigned: cmb (profile)
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.3.3 OS: linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-08-24 13:45 UTC] 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




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-12 18:33 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2016-08-12 18:33 UTC] cmb@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 01:01:30 2024 UTC