|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-07-15 03:50 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 14:00:01 2025 UTC |
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; ?>