Jasper Bryant-Greene wrote:
Jochem Maas wrote:
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:
echo $tc->arr['a']
this is triggers a call to __get() with the $key parameter set to
something like
(I'm guessing) "arr['a']"
No, I'm pretty sure (too lazy and tired right now to test...) that if
you guess wrong :-) .. I couldn't resist testing it:
php -r '
class T { private $var = array();
function __set($k, $v) { $this->var[$k] = $v; }
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php