Re: Overloading Limitation- Can Someone Confirm?
| From: | Jochem Maas | Date: | Thu, 30 Mar 2006 14:53:07 +0000 |
| Subject: | Re: Overloading Limitation- Can Someone Confirm? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-232928@lists.php.net to get a copy of this message | ||
Jasper Bryant-Greene wrote:
Jochem Maas wrote:you guess wrong :-) .. I couldn't resist testing it: php -r ' class T { private $var = array(); function __set($k, $v) { $this->var[$k] = $v; }I think its a misunderstanding on the one side and a limitation on the other, you can't use overloading directly on items of an overloaded array e.g:No, I'm pretty sure (too lazy and tired right now to test...) that ifecho $tc->arr['a']this is triggers a call to __get() with the $key parameter set to something like (I'm guessing) "arr['a']"
function __get($k) { var_dump($k); }
}
$t = new T;
$t->arr = array();
$t->arr["a"] = 1;
echo "OUTPUT: \n"; var_dump($t->arr); var_dump($t->arr["a"]); var_dump($t);
'
things work as they should, it will look up __get() with the key parameter set to 'arr', and treat the return value of that as an array, looking for the 'a' key inside that array. Or at least it should, dammit.really should it? if you had written this engine functionality yourself and it did not work as you intended I could understand yuor remark - but I'm pretty sure you didn't write it. It's very simple to state something should work a certain way - you'll probably find it rahter harder to actually make the core engine handle stuff like this in way that ... a: is robust b: is intuitive to most people c: actually works