xref: /php-src/Zend/tests/bug67633.phpt (revision 5e977e69)
1--TEST--
2Bug #67633: A foreach on an array returned from a function not doing copy-on-write
3--FILE--
4<?php
5
6function id($x) {
7    return $x;
8}
9
10function &ref_id(&$x) {
11    return $x;
12}
13
14$c = 'c';
15$array = ['a', 'b', $c];
16
17foreach(id($array) as &$v) {
18    $v .= 'q';
19}
20var_dump($array);
21
22foreach(ref_id($array) as &$v) {
23    $v .= 'q';
24}
25var_dump($array);
26
27?>
28--EXPECT--
29array(3) {
30  [0]=>
31  string(1) "a"
32  [1]=>
33  string(1) "b"
34  [2]=>
35  string(1) "c"
36}
37array(3) {
38  [0]=>
39  string(2) "aq"
40  [1]=>
41  string(2) "bq"
42  [2]=>
43  &string(2) "cq"
44}
45