shire           Mon Jan 14 22:09:52 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/standard/tests/array   bug42850.phpt 

  Modified files:              
    /php-src/ext/standard       array.c 
  Log:
  MFH: Fix bug #42850 array_walk_recursive() leaves references, refix bug #34982
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/array.c?r1=1.308.2.21.2.37.2.13&r2=1.308.2.21.2.37.2.14&diff_format=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.308.2.21.2.37.2.13 
php-src/ext/standard/array.c:1.308.2.21.2.37.2.14
--- php-src/ext/standard/array.c:1.308.2.21.2.37.2.13   Mon Dec 31 07:17:14 2007
+++ php-src/ext/standard/array.c        Mon Jan 14 22:09:52 2008
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: array.c,v 1.308.2.21.2.37.2.13 2007/12/31 07:17:14 sebastian Exp $ */
+/* $Id: array.c,v 1.308.2.21.2.37.2.14 2008/01/14 22:09:52 shire Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -1038,7 +1038,7 @@
                        zend_fcall_info orig_array_walk_fci;
                        zend_fcall_info_cache orig_array_walk_fci_cache;
 
-                       SEPARATE_ZVAL_TO_MAKE_IS_REF(args[0]);
+                       SEPARATE_ZVAL_IF_NOT_REF(args[0]);
                        thash = HASH_OF(*(args[0]));
                        if (thash->nApplyCount > 1) {
                                php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"recursion detected");

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/bug42850.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/bug42850.phpt
+++ php-src/ext/standard/tests/array/bug42850.phpt
--TEST--
Bug #42850 array_walk_recursive() leaves references, #34982 
array_walk_recursive() modifies elements outside function scope 
--FILE--
<?php

// Bug #42850
$data = array ('key1' => 'val1', array('key2' => 'val2'));
function apply_dumb($item, $key) {}; 
var_dump($data);
array_walk_recursive($data, 'apply_dumb');
$data2 = $data;
$data2[0] = 'altered';
var_dump($data);
var_dump($data2);

// Bug #34982
function myfunc($data) {
    array_walk_recursive($data, 'apply_changed');
}
function apply_changed(&$input, $key) {
    $input = 'changed';
}
myfunc($data);
var_dump($data);

--EXPECT--
array(2) {
  ["key1"]=>
  string(4) "val1"
  [0]=>
  array(1) {
    ["key2"]=>
    string(4) "val2"
  }
}
array(2) {
  ["key1"]=>
  string(4) "val1"
  [0]=>
  array(1) {
    ["key2"]=>
    string(4) "val2"
  }
}
array(2) {
  ["key1"]=>
  string(4) "val1"
  [0]=>
  string(7) "altered"
}
array(2) {
  ["key1"]=>
  string(4) "val1"
  [0]=>
  array(1) {
    ["key2"]=>
    string(4) "val2"
  }
}
--UEXPECT--
array(2) {
  [u"key1"]=>
  unicode(4) "val1"
  [0]=>
  array(1) {
    [u"key2"]=>
    unicode(4) "val2"
  }
}
array(2) {
  [u"key1"]=>
  unicode(4) "val1"
  [0]=>
  array(1) {
    [u"key2"]=>
    unicode(4) "val2"
  }
}
array(2) {
  [u"key1"]=>
  unicode(4) "val1"
  [0]=>
  unicode(7) "altered"
}
array(2) {
  [u"key1"]=>
  unicode(4) "val1"
  [0]=>
  array(1) {
    [u"key2"]=>
    unicode(4) "val2"
  }
}

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to