summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorMoriyoshi Koizumi <moriyoshi@php.net>2005-01-02 06:51:03 +0000
committerMoriyoshi Koizumi <moriyoshi@php.net>2005-01-02 06:51:03 +0000
commit88ce94a3c2a9fca658add5eb8fca38674fa7a0b8 (patch)
tree0e930c9205934a7fdfd849444076a57303a02706 /ext
parentfc64a7ae57ce74cfa3c0d0d7ccbb9e0870f4d274 (diff)
downloadphp-git-88ce94a3c2a9fca658add5eb8fca38674fa7a0b8.tar.gz
- Add testcases for bug #29493 and #31213.
Diffstat (limited to 'ext')
-rw-r--r--ext/standard/tests/array/bug29493.phpt115
-rw-r--r--ext/standard/tests/array/bug31213.phpt55
2 files changed, 170 insertions, 0 deletions
diff --git a/ext/standard/tests/array/bug29493.phpt b/ext/standard/tests/array/bug29493.phpt
new file mode 100644
index 0000000000..0cfe45910b
--- /dev/null
+++ b/ext/standard/tests/array/bug29493.phpt
@@ -0,0 +1,115 @@
+--TEST--
+Bug #29493 (extract(EXTR_REFS) fails if array has multiple referrals)
+--FILE--
+<?php
+function t1()
+{
+ $a = array('foo' => 'aaa');
+ // refcount($a) = 1
+ // refcount($a['foo']) = 1
+ $b = $a;
+ // refcount($a) = 2
+ // refcount($a['foo']) = 1
+ $b['foo'] = 'bbb';
+ // refcount($a) = 1
+ // refcount($a['foo']) = 1
+
+ var_dump($a, $b);
+
+ extract($a, EXTR_REFS);
+
+ $foo = 'noo';
+
+ var_dump($a, $b);
+}
+
+function t2()
+{
+ $a = array('foo' => 'aaa');
+ // refcount($a) = 1
+ // refcount($a['foo']) = 1
+ $b = &$a;
+ // refcount($a) = 2
+ // is_ref($a) = true
+ // refcount($a['foo']) = 1
+ $b['foo'] = 'bbb';
+ // refcount($a) = 2
+ // refcount($a['foo']) = 1
+
+ var_dump($a, $b);
+
+ extract($a, EXTR_REFS);
+
+ $foo = 'noo';
+
+ var_dump($a, $b);
+}
+
+function t3()
+{
+ $a = array('foo' => 'aaa');
+ // refcount($a) = 1
+ // refcount($a['foo']) = 1
+ $b = &$a;
+ // refcount($a) = 2
+ // is_ref($a) = true
+ // refcount($a['foo']) = 1
+ unset($b);
+ // refcount($a) = 1
+ // is_ref($a) = true
+ // refcount($a['foo']) = 1
+
+ var_dump($a);
+
+ extract($a, EXTR_REFS);
+
+ $foo = 'noo';
+
+ var_dump($a);
+}
+
+t1();
+t2();
+t3();
+?>
+--EXPECT--
+array(1) {
+ ["foo"]=>
+ string(3) "aaa"
+}
+array(1) {
+ ["foo"]=>
+ string(3) "bbb"
+}
+array(1) {
+ ["foo"]=>
+ &string(3) "noo"
+}
+array(1) {
+ ["foo"]=>
+ string(3) "bbb"
+}
+array(1) {
+ ["foo"]=>
+ string(3) "bbb"
+}
+array(1) {
+ ["foo"]=>
+ string(3) "bbb"
+}
+array(1) {
+ ["foo"]=>
+ &string(3) "noo"
+}
+array(1) {
+ ["foo"]=>
+ &string(3) "noo"
+}
+array(1) {
+ ["foo"]=>
+ string(3) "aaa"
+}
+array(1) {
+ ["foo"]=>
+ &string(3) "noo"
+}
diff --git a/ext/standard/tests/array/bug31213.phpt b/ext/standard/tests/array/bug31213.phpt
new file mode 100644
index 0000000000..55ad88110d
--- /dev/null
+++ b/ext/standard/tests/array/bug31213.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Bug #31213 (Sideeffects caused by bug #29493)
+--FILE--
+<?php
+function test($use_extract) {
+ $a = 1;
+ $b = 1;
+
+ $arr = array(
+ '_a' => $a,
+ '_b' => &$b
+ );
+
+ var_dump($a, $b);
+
+ if ($use_extract) {
+ extract($arr, EXTR_REFS);
+ } else {
+ $_a = &$arr['_a'];
+ $_b = &$arr['_b'];
+ }
+
+ $_a++;
+ $_b++;
+
+ var_dump($a, $b, $_a, $_b, $arr);
+}
+
+test(false);
+test(true);
+--EXPECT--
+int(1)
+int(1)
+int(1)
+int(2)
+int(2)
+int(2)
+array(2) {
+ ["_a"]=>
+ &int(2)
+ ["_b"]=>
+ &int(2)
+}
+int(1)
+int(1)
+int(1)
+int(2)
+int(2)
+int(2)
+array(2) {
+ ["_a"]=>
+ &int(2)
+ ["_b"]=>
+ &int(2)
+}