|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-11-17 14:04 UTC] dckorah at gmail dot com
Description:
------------
<?php
class A {
function __construct() {
$this->a_property = 'property set from A';
}
}
class B {
function __construct() {
A::__construct();
$this->b_property = 'property set from B';
}
}
?>
In the above code, if you initialise class B and inspect the properties of it, you will see that both a_property and b_property are set.
This is quite unexpected from an OO language.
version info:
PHP 5.2.3-1ubuntu6.4 (cli) (built: Jul 23 2008 06:20:35)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
Reproduce code:
---------------
<?php
class A {
function __construct() {
$this->a_property = 'property set from A';
}
}
class B {
function __construct() {
A::__construct();
$this->b_property = 'property set from B';
}
}
?>
Expected result:
----------------
Class A has got nothing to do with class B and this should not happen. If at all an user trys this, it should throw an error.
Actual result:
--------------
Please see description.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 07:00:01 2025 UTC |
This is actually fixed in PHP_5_3 branch already: [jani@localhost ~]$ src/build/php_5_3/sapi/cli/php -n t.php Fatal error: Non-static method A::__construct() cannot be called statically, assuming $this from incompatible context in /home/jani/t.php on line 11 [jani@localhost ~]$ src/build/php_5_2/sapi/cli/php -n t.php object(B)#1 (2) { ["a_property"]=> string(19) "property set from A" ["b_property"]=> string(19) "property set from B" }