|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-08-09 13:22 UTC] 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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 22:00:02 2025 UTC |
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.Nuts, typo. Both the `Users` should start: class Users extends users_base {