note 39288 deleted from ref.overload by sobak

From: Date: Tue, 22 Nov 2016 03:49:01 +0000
Subject: note 39288 deleted from ref.overload by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207445@lists.php.net to get a copy of this message
Note Submitter: sdavey at datalink dot net dot au ---- 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.

« previous php.notes (#207445) next »