note 39288 added to ref.overload
| From: | sdavey at datalink dot net dot au | Date: | Fri, 23 Jan 2004 06:45:36 +0000 |
| Subject: | note 39288 added to ref.overload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64055@lists.php.net to get a copy of this message | ||
It wasn't quite clear, but I found out that __get() and __set() only overload attributes that
_don't_ exist.
For example:
<?
class Foo
{
var $a = "normal attribute";
function __get($key, &$ret)
{
$ret = "overloaded return value";
return true;
}
}
overload("Foo");
$foo = new Foo();
print "get a: $foo->a \n"; // prints: get a: normal attribute
print "get b: $foo->b \n"; // prints: get b: overloaded return value
?>
The important thing to note here is that $foo->a did not pass through __get(), because the
attibute has been defined.
So it's more like "underloading" than "overloading", as it only virtualises
attributes that _do not_ exist.
----
Manual Page -- http://www.php.net/manual/en/ref.overload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39288
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39288&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39288&report=yes
Search -- http://master.php.net/manage/user-notes.php