Annotation of embedaddon/php/Zend/tests/bug39944.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Bug #39944 (References broken)
3: --FILE--
4: <?php
5: $intTheValue = 0;
6:
7: function &getValue() {
8: global $intTheValue;
9: return $intTheValue;
10: }
11:
12: function setValue(&$int, $iNewValue) {
13: $int = $iNewValue;
14: }
15:
16: setValue(getValue(), 10);
17: echo "intTheValue = {$intTheValue}\n";
18:
19: $b = &$intTheValue;
20:
21: setValue(getValue(), 10);
22: echo "intTheValue = {$intTheValue}\n";
23:
24: /****/
25:
26: $arrTheArray = array();
27:
28: function &getArray() {
29: global $arrTheArray;
30: return $arrTheArray;
31: }
32:
33: function addToArray(&$arr, $strToAdd) {
34: $arr[] = $strToAdd;
35: }
36:
37: addToArray(getArray(), "xx1");
38: $a = getArray();
39: addToArray($a, "xx2");
40: $b = &$arrTheArray;
41: addToArray($b, "xx3");
42: addToArray(getArray(), "xx4");
43: $a = getArray();
44: addToArray($a, "xx5");
45: echo "arrTheArray = " . print_r($arrTheArray, 1);
46:
47: /****/
48:
49: class 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:
72: echo "objRefTest->getArray() = " . print_r($objRefTest->getArray(), 1);
73: ?>
74: --EXPECT--
75: intTheValue = 10
76: intTheValue = 10
77: arrTheArray = Array
78: (
79: [0] => xx1
80: [1] => xx3
81: [2] => xx4
82: )
83: objRefTest->getArray() = Array
84: (
85: [0] => xx1
86: [1] => xx2
87: [2] => xx3
88: )
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>