From:             
Operating system: linux
PHP version:      5.3.3
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:parent::__construct in extended classes - not downward 
compatible change

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 bug report at http://bugs.php.net/bug.php?id=52687&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=52687&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=52687&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=52687&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=52687&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=52687&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=52687&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=52687&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=52687&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=52687&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=52687&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=52687&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=52687&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=52687&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=52687&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=52687&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=52687&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=52687&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=52687&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=52687&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=52687&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=52687&r=mysqlcfg

Reply via email to