On Thu, 02 Sep 2004, Curt Zirzow wrote:
> Test 1: ($file holds last type conversion)
> <?php
> foreach (new DirectoryIterator('.') as $file) {
> echo "\n--\n";
> var_dump($file);
> preg_match("/xxx/", $file);
> var_dump($file);
> echo "\n--";
> }
>
> Output:
> Object(DirectoryIterator)#1 (0) {
> }
> string(1) "."
> --
> --
> string(1) "."
> string(1) "."
> --
> ...
The culprit is this piece of code in zend_parse_arg_impl():
case IS_OBJECT: {
if (Z_OBJ_HANDLER_PP(arg, cast_object)
&& Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_STRING, 0
TSRMLS_CC) == SUCCESS) {
*pl = Z_STRLEN_PP(arg);
*p = Z_STRVAL_PP(arg);
break;
}
The cast_object handler overwrites the value in *arg and that's why the
original variable changes type. I think Andi made this change on Dec 02,
2003. I can see the rationale behind not using a new var for the
conversion, because then we have to keep track of it and release it
somehow, but changing variable types is not good either. Andi, any
suggestions?
- Andrei
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php