]> granicus.if.org Git - php/commitdiff
Fixed bug #71603 (compact() maintains references in php7)
authorXinchen Hui <laruence@gmail.com>
Tue, 16 Feb 2016 03:02:57 +0000 (11:02 +0800)
committerXinchen Hui <laruence@gmail.com>
Tue, 16 Feb 2016 03:02:57 +0000 (11:02 +0800)
NEWS
ext/standard/array.c
ext/standard/tests/array/bug71603.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 15667a6958cec76b292c74d097211c88cdf0df8b..eae72f046d3200a33aee88fc82dabfff2ded1e19 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -54,6 +54,7 @@ PHP                                                                        NEWS
     phpdbg_get_executable(). (Bob)
 
 - Standard:
+  . Fixed bug #71603 (compact() maintains references in php7). (Laruence)
   . Fixed bug #70720 (strip_tags improper php code parsing). (Julien)
 
 - XMLRPC:
index cd058ae68ad492c9ba806de51ff750d76530c7b8..5add302c4636c0542faaed030d91265a4928176f 100644 (file)
@@ -1944,6 +1944,7 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu
        ZVAL_DEREF(entry);
        if (Z_TYPE_P(entry) == IS_STRING) {
                if ((value_ptr = zend_hash_find_ind(eg_active_symbol_table, Z_STR_P(entry))) != NULL) {
+                       ZVAL_DEREF(value_ptr);
                        ZVAL_COPY(&data, value_ptr);
                        zend_hash_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
                }
diff --git a/ext/standard/tests/array/bug71603.phpt b/ext/standard/tests/array/bug71603.phpt
new file mode 100644 (file)
index 0000000..0c25be6
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Bug #71603 (compact() maintains references in php7)
+--FILE--
+<?php
+$foo = "okey";
+$foo_reference =& $foo;
+
+$array = compact('foo_reference');
+
+$foo = 'changed!';
+
+var_dump($array['foo_reference']);
+
+--EXPECT--
+string(4) "okey"