summaryrefslogtreecommitdiff
path: root/Zend/tests/list/list_reference_008.phpt
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/tests/list/list_reference_008.phpt')
-rw-r--r--Zend/tests/list/list_reference_008.phpt68
1 files changed, 68 insertions, 0 deletions
diff --git a/Zend/tests/list/list_reference_008.phpt b/Zend/tests/list/list_reference_008.phpt
new file mode 100644
index 0000000000..9c754a698d
--- /dev/null
+++ b/Zend/tests/list/list_reference_008.phpt
@@ -0,0 +1,68 @@
+--TEST--
+"Reference Unpacking - Oddities" list()
+--FILE--
+<?php
+$a = 1;
+$b =& $a;
+$arr = [&$a, &$b];
+list(&$a, &$b) = $arr;
+var_dump($a, $b, $arr);
+$b++;
+var_dump($a, $b, $arr);
+unset($a, $b, $arr);
+
+/*
+ * $a is first set as a reference to the 0'th elem, '1'
+ * $a is then set to the value of the 1'st elem, '2'
+ * $arr would look like, [2,2]
+ * Increment $a, and it should be [3, 2]
+ */
+$arr = [1, 2];
+list(&$a, $a) = $arr;
+var_dump($a);
+$a++;
+var_dump($arr);
+unset($a, $arr);
+
+/*
+ * We do not allow references to the same variable of rhs.
+ */
+$a = [1, 2];
+$ref =& $a;
+list(&$a, &$b) = $a;
+var_dump($a, $b);
+$a++; $b++;
+var_dump($ref);
+?>
+--EXPECTF--
+int(1)
+int(1)
+array(2) {
+ [0]=>
+ &int(1)
+ [1]=>
+ &int(1)
+}
+int(2)
+int(2)
+array(2) {
+ [0]=>
+ &int(2)
+ [1]=>
+ &int(2)
+}
+int(2)
+array(2) {
+ [0]=>
+ &int(3)
+ [1]=>
+ int(2)
+}
+int(1)
+int(2)
+array(2) {
+ [0]=>
+ &int(2)
+ [1]=>
+ &int(3)
+}