#29174 [Opn->Bgs]: __get and __set are not called when placed in a class that has a parent class
| From: | helly@php.net | Date: | Fri, 23 Jul 2004 05:56:33 +0000 |
| Subject: | #29174 [Opn->Bgs]: __get and __set are not called when placed in a class that has a parent class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-63401@lists.php.net to get a copy of this message | ||
ID: 29174
Updated by: helly@php.net
Reported By: jbeall at heraldic dot us
-Status: Open
+Status: Bogus
Bug Type: Zend Engine 2 problem
-Operating System: Linux
+Operating System: *
PHP Version: 5.0.0
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
Move get/set to base class.
Previous Comments:
------------------------------------------------------------------------
[2004-07-23 06:46:18] imprestavel at gameguru dot com dot br
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;
?>
------------------------------------------------------------------------
[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