xref: /PHP-7.0/Zend/tests/bug39944.phpt (revision 610c7fbe)
1--TEST--
2Bug #39944 (References broken)
3--FILE--
4<?php
5$intTheValue = 0;
6
7function &getValue() {
8    global $intTheValue;
9    return $intTheValue;
10}
11
12function setValue(&$int, $iNewValue) {
13    $int = $iNewValue;
14}
15
16setValue(getValue(), 10);
17echo "intTheValue = {$intTheValue}\n";
18
19$b = &$intTheValue;
20
21setValue(getValue(), 10);
22echo "intTheValue = {$intTheValue}\n";
23
24/****/
25
26$arrTheArray = array();
27
28function &getArray() {
29	global $arrTheArray;
30	return $arrTheArray;
31}
32
33function addToArray(&$arr, $strToAdd) {
34	$arr[] = $strToAdd;
35}
36
37addToArray(getArray(), "xx1");
38$a = getArray();
39addToArray($a, "xx2");
40$b = &$arrTheArray;
41addToArray($b, "xx3");
42addToArray(getArray(), "xx4");
43$a = getArray();
44addToArray($a, "xx5");
45echo "arrTheArray = " . print_r($arrTheArray, 1);
46
47/****/
48
49class RefTest {
50	protected $arr;
51
52	function Add($strToAdd) {
53		$this->addToArray($this->getArray(), $strToAdd);
54	}
55
56	function &getArray() {
57		if (!$this->arr)
58			$this->arr = array();
59		return $this->arr;
60	}
61
62	private function addToArray(&$arr, $strToAdd) {
63		$arr[] = $strToAdd;
64	}
65}
66
67$objRefTest = new RefTest();
68$objRefTest->Add("xx1");
69$objRefTest->Add("xx2");
70$objRefTest->Add("xx3");
71
72echo "objRefTest->getArray() = " . print_r($objRefTest->getArray(), 1);
73?>
74--EXPECT--
75intTheValue = 10
76intTheValue = 10
77arrTheArray = Array
78(
79    [0] => xx1
80    [1] => xx3
81    [2] => xx4
82)
83objRefTest->getArray() = Array
84(
85    [0] => xx1
86    [1] => xx2
87    [2] => xx3
88)
89