]> granicus.if.org Git - php/commitdiff
Fixed bug #22224 (implode changes object references in array)
authorMoriyoshi Koizumi <moriyoshi@php.net>
Fri, 14 Feb 2003 18:42:36 +0000 (18:42 +0000)
committerMoriyoshi Koizumi <moriyoshi@php.net>
Fri, 14 Feb 2003 18:42:36 +0000 (18:42 +0000)
Added test case for the bug

ext/standard/string.c
ext/standard/tests/strings/bug22224.phpt [new file with mode: 0644]

index bbdb38abe8b684174ee7b6b06987d66d1f03da08..e5788dcf1b371c18f98a0e8863be5a4b3d63203a 100644 (file)
@@ -835,7 +835,8 @@ PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value)
        zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
 
        while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **) &tmp, &pos) == SUCCESS) {
-               convert_to_string_ex(tmp);
+               SEPARATE_ZVAL(tmp);
+               convert_to_string(*tmp);
 
                smart_str_appendl(&implstr, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
                if (++i != numelems) {
diff --git a/ext/standard/tests/strings/bug22224.phpt b/ext/standard/tests/strings/bug22224.phpt
new file mode 100644 (file)
index 0000000..fea9455
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Bug #22224 (implode changes object references in array)
+--INI--
+error_reporting=0
+--FILE--
+<?php
+class foo {
+}
+
+
+$a = new foo();
+                           
+$arr = array(0=>&$a, 1=>&$a);
+var_dump(implode(",",$arr));
+var_dump($arr)
+?>
+--EXPECT--
+string(13) "Object,Object"
+array(2) {
+  [0]=>
+  &object(foo)(0) {
+  }
+  [1]=>
+  &object(foo)(0) {
+  }
+}