#42256 [Com]: PHP4 backwards-compatibility slightly broken

From: Date: Fri, 10 Aug 2007 01:25:44 +0000
Subject: #42256 [Com]: PHP4 backwards-compatibility slightly broken
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969377315@lists.php.net to get a copy of this message
ID: 42256 Comment by: judas dot iscariote at gmail dot com Reported By: mat at bcclimited dot co dot uk Status: Open Bug Type: Documentation problem Operating System: Windows, Linux PHP Version: 5.2.4RC1 New Comment: Interesting ;) the documentation should also mention that the old PHP4 beahviuor is clearly the wrong thing. Previous Comments: ------------------------------------------------------------------------ [2007-08-09 15:01:28] jani@php.net Reclassified. ------------------------------------------------------------------------ [2007-08-09 13:40:03] mat at bcclimited dot co dot uk Nuts, typo. Both the Users should start: class Users extends users_base { ------------------------------------------------------------------------ [2007-08-09 13:26:22] mat at bcclimited dot co dot uk Oh, thought I'd add a workaround: class Users { function Users() { parent::Users(); } } Unfortunately for me, there are one hell of a lot of classes that our previous programmer built in this fashion, making the workaround impractical. ------------------------------------------------------------------------ [2007-08-09 13:22:18] mat at bcclimited dot co dot uk Description: ------------ PHP4-style constructors do not function, in PHP5, in the same way as they do in PHP4. The issue lies in when parent constructors are called, or not as the case may be. Reproduce code: --------------- class users_base { function Users() { echo "users_base::Users()\n"; } } class Users { // Nothing here. } $base = new users_base(); $child = new Users(); Expected result: ---------------- Running the sample code in PHP4 will give the expected result: users_base::Users() users_base::Users() Whereas PHP5 will not call the Users() function in the parent class: users_base::Users() I class this as a bug because of the expected PHP5 behaviour as well as the evident PHP4 behaviour. If the users_base function is renamed to __construct(), it will get called on BOTH instantiations, as PHP4 does with its style. Actual result: -------------- users_base::Users() (The child class does not call Users() on instantiation) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42256&edit=1

« previous php.doc (#969377315) next »