Re: Directoryiterator / preg_match behavior

From: Date: Sat, 04 Sep 2004 01:17:55 +0000
Subject: Re: Directoryiterator / preg_match behavior
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-12570@lists.php.net to get a copy of this message
It probably makes sense to add SEPARATE_ZVAL_IF_NOT_REF() to that code. This would provide the same behavior as for example for long's. Can you please check out the following patch? Index: zend_API.c =================================================================== RCS file: /repository/ZendEngine2/zend_API.c,v retrieving revision 1.257 diff -u -r1.257 zend_API.c
--- zend_API.c  24 Aug 2004 18:47:18 -0000      1.257
+++ zend_API.c 4 Sep 2004 01:17:19 -0000 @@ -318,6 +318,7 @@
                                        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) {
+ SEPARATE_ZVAL_IF_NOT_REF(arg);
                                                        *pl = Z_STRLEN_PP(arg);
                                                        *p = Z_STRVAL_PP(arg);
                                                        break;
At 10:43 AM 9/2/2004 -0700, Andrei Zmievski wrote:
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


« previous php.internals (#12570) next »