object-overloading: why not allow recursive calls? (5.1) hey, in zend_object_handlers.c function zend_std_read_property we protect against calling
the __get function of an object if we're already in a __get() function. (look for zobj->in_get) in that function. i don't think we should be doing
this. simplyfied example: <?php class test { function __get($offset) { echo "__get($offset)\n"; switch ($offset) {
case 'name': return "name"; case 'length': return strlen($this->name); } } } $a = new test; var_dump($a->length); ?>
outputs: __get(length) int(0) but should say: __get(length) __get(name) int(4) i think recursive gets are highly useful and should be allowed. if we
really want to protect against recursion (here) we have two real options: -a- protect against __get(ing) the same property more than once in the same
call-chain (mucho work), or -b- (preferred) have some global infinite recursion protection in the engine (needs to be done somewhen anyhow, but not
now). so, in one sentence: as we don't protect against recustion elsewhere, can we please remove this unneded roadblock? opinions? -thies
| From: | Thies C. Arntzen | Date: | Fri, 04 Nov 2005 08:35:08 +0000 |
| Subject: | object-overloading: why not allow recursive calls? (5.1) hey, in zend_object_handlers.c function zend_std_read_property we protect against calling the __get function of an object if we're already in a __get() function. (look for zobj->in_get) in that function. i don't think we should be doing this. simplyfied example: <?php class test { function __get($offset) { echo "__get($offset)\n"; switch ($offset) { case 'name': return "name"; case 'length': return strlen($this->name); } } } $a = new test; var_dump($a->length); ?> outputs: __get(length) int(0) but should say: __get(length) __get(name) int(4) i think recursive gets are highly useful and should be allowed. if we really want to protect against recursion (here) we have two real options: -a- protect against __get(ing) the same property more than once in the same call-chain (mucho work), or -b- (preferred) have some global infinite recursion protection in the engine (needs to be done somewhen anyhow, but not now). so, in one sentence: as we don't protect against recustion elsewhere, can we please remove this unneded roadblock? opinions? -thies |
||
| Groups: | php.internals php.internals | ||
| Request: | Send a blank email to internals+get-19904@lists.php.net to get a copy of this message | ||
hey,
in zend_object_handlers.c function zend_std_read_property we protect against calling the __get function of an object if we're already in a __get() function. (look for zobj->in_get) in that function.
i don't think we should be doing this.
simplyfied example:
<?php
class test {
function __get($offset) {
echo "__get($offset)\n";
switch ($offset) {
case 'name': return "name";
case 'length': return strlen($this->name);
}
}
}
$a = new test;
var_dump($a->length);
?>
outputs:
__get(length)
int(0)
but should say:
__get(length)
__get(name)
int(4)
i think recursive gets are highly useful and should be allowed. if we really want to protect against recursion (here) we have two real options: -a- protect against __get(ing) the same property more than once in the same call-chain (mucho work), or -b- (preferred) have some global infinite recursion protection in the engine (needs to be done somewhen anyhow, but not now).
so, in one sentence: as we don't protect against recustion elsewhere, can we please remove this unneded roadblock?
opinions?
-thies