Bug #51888 [Opn->Bgs]: overloaded __set is called from parent class
Edit report at http://bugs.php.net/bug.php?id=51888&edit=1
ID: 51888
Updated by: mike@php.net
Reported by: j dot jeising at gmail dot com
Summary: overloaded __set is called from parent class
-Status: Open
+Status: Bogus
Type: Bug
Package: Class/Object related
Operating System: Mac OS X
PHP Version: 5.3.2
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
YOU call parent::__set() which assigns an unkown property, which in turn
calls the __set() of the child.
Jeeeeez
Previous Comments:
------------------------------------------------------------------------
[2010-05-22 17:17:11] j dot jeising at gmail dot com
Description:
------------
If you overwrite __set in a child class, the parent implementation is
called first
and than triggers the child version.
I found another bug, which says that you should implement the __set
method in the
parent class, but it in this case both methods are called.
A similar bug is reported in #44807, but it's only about the recursion
prevention.
Test script:
---------------
<?php
class Foo {
function __set($key, $value) {
$this->{$key} = $value . ' (Foo)';
}
}
class Bar extends Foo {
function __set($key, $value) {
$this->{$key} = $value . ' (Bar)';
}
function set() {
parent::__set('foobar', 'Test');
}
}
$bar = new Bar();
$bar->set();
echo $bar->foobar;
?>
Expected result:
----------------
Test (Foo)
Actual result:
--------------
Test (Foo) (Bar)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51888&edit=1
Thread (2 messages)