ID: 29174
Comment by: imprestavel at gameguru dot com dot br
Reported By: jbeall at heraldic dot us
Status: Open
Bug Type: Zend Engine 2 problem
Operating System: Linux
PHP Version: 5.0.0
New Comment:
i think extends works the other way around
"class Super extends Sub", means that Super will inherit Sub stuff, not
the opposite
so, when you do:
> $foo = new Sub();
you are instantiating Sub, which doesn't inherit Super, ending up
without the __get and __set methods
try:
<?
class Super
{
function __get($prop)
{
echo "Property $prop called\n";
}
function __set($prop, $val)
{
echo "Property $prop set to $val\n";
}
}
class Sub extends Super
{
}
$foo = new Sub();
$foo->someProp = 10;
echo $foo->someProp;
?>
Previous Comments:
------------------------------------------------------------------------
[2004-07-15 03:50:59] jbeall at heraldic dot us
Description:
------------
the __get() and __set() functions work fine to overload a class when
that class has no parent class. However, if the class you put __get()
and __set() in has a parent class, they are not called whenever a
property is called.
Reproduce code:
---------------
class Sub
{
}
class Super extends Sub
{
function __get($prop)
{
echo "Property $prop called\n";
}
function __set($prop, $val)
{
echo "Property $prop set to $val\n";
}
}
$foo = new Sub();
$foo->someProp = 10;
echo $foo->someProp;
Expected result:
----------------
Property someProp set to 10
Property someProp called
Actual result:
--------------
10
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29174&edit=1