1--TEST-- 2Pass uninitialised objects and arrays by reference to test implicit initialisation. 3--FILE-- 4<?php 5 6function refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { 7 $ref1 = "Ref1 changed"; 8 $ref2 = "Ref2 changed"; 9 $ref3 = "Ref3 changed"; 10 $ref4 = "Ref4 changed"; 11 $ref5 = "Ref5 changed"; 12} 13 14 15class C { 16 17 function __construct(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { 18 $ref1 = "Ref1 changed"; 19 $ref2 = "Ref2 changed"; 20 $ref3 = "Ref3 changed"; 21 $ref4 = "Ref4 changed"; 22 $ref5 = "Ref5 changed"; 23 } 24 25 function refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { 26 $ref1 = "Ref1 changed"; 27 $ref2 = "Ref2 changed"; 28 $ref3 = "Ref3 changed"; 29 $ref4 = "Ref4 changed"; 30 $ref5 = "Ref5 changed"; 31 } 32 33} 34 35echo "\n ---- Pass uninitialised array & object by ref: function call ---\n"; 36unset($u1, $u2, $u3, $u4, $u5); 37refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); 38var_dump($u1, $u2, $u3, $u4, $u5); 39 40echo "\n ---- Pass uninitialised arrays & objects by ref: static method call ---\n"; 41unset($u1, $u2, $u3, $u4, $u5); 42C::refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); 43var_dump($u1, $u2, $u3, $u4, $u5); 44 45echo "\n\n---- Pass uninitialised arrays & objects by ref: constructor ---\n"; 46unset($u1, $u2, $u3, $u4, $u5); 47$c = new C($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); 48var_dump($u1, $u2, $u3, $u4, $u5); 49 50echo "\n ---- Pass uninitialised arrays & objects by ref: instance method call ---\n"; 51unset($u1, $u2, $u3, $u4, $u5); 52$c->refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); 53var_dump($u1, $u2, $u3, $u4, $u5); 54 55?> 56--EXPECTF-- 57 ---- Pass uninitialised array & object by ref: function call --- 58array(1) { 59 [0]=> 60 string(12) "Ref1 changed" 61} 62array(1) { 63 [0]=> 64 array(1) { 65 [1]=> 66 string(12) "Ref2 changed" 67 } 68} 69object(stdClass)#%d (1) { 70 ["a"]=> 71 string(12) "Ref3 changed" 72} 73object(stdClass)#%d (1) { 74 ["a"]=> 75 object(stdClass)#%d (1) { 76 ["b"]=> 77 string(12) "Ref4 changed" 78 } 79} 80object(stdClass)#%d (1) { 81 ["a"]=> 82 object(stdClass)#%d (1) { 83 ["b"]=> 84 object(stdClass)#%d (1) { 85 ["c"]=> 86 string(12) "Ref5 changed" 87 } 88 } 89} 90 91 ---- Pass uninitialised arrays & objects by ref: static method call --- 92 93Deprecated: Non-static method C::refs() should not be called statically in %s on line 39 94array(1) { 95 [0]=> 96 string(12) "Ref1 changed" 97} 98array(1) { 99 [0]=> 100 array(1) { 101 [1]=> 102 string(12) "Ref2 changed" 103 } 104} 105object(stdClass)#%d (1) { 106 ["a"]=> 107 string(12) "Ref3 changed" 108} 109object(stdClass)#%d (1) { 110 ["a"]=> 111 object(stdClass)#%d (1) { 112 ["b"]=> 113 string(12) "Ref4 changed" 114 } 115} 116object(stdClass)#%d (1) { 117 ["a"]=> 118 object(stdClass)#%d (1) { 119 ["b"]=> 120 object(stdClass)#%d (1) { 121 ["c"]=> 122 string(12) "Ref5 changed" 123 } 124 } 125} 126 127 128---- Pass uninitialised arrays & objects by ref: constructor --- 129array(1) { 130 [0]=> 131 string(12) "Ref1 changed" 132} 133array(1) { 134 [0]=> 135 array(1) { 136 [1]=> 137 string(12) "Ref2 changed" 138 } 139} 140object(stdClass)#%d (1) { 141 ["a"]=> 142 string(12) "Ref3 changed" 143} 144object(stdClass)#%d (1) { 145 ["a"]=> 146 object(stdClass)#%d (1) { 147 ["b"]=> 148 string(12) "Ref4 changed" 149 } 150} 151object(stdClass)#%d (1) { 152 ["a"]=> 153 object(stdClass)#%d (1) { 154 ["b"]=> 155 object(stdClass)#%d (1) { 156 ["c"]=> 157 string(12) "Ref5 changed" 158 } 159 } 160} 161 162 ---- Pass uninitialised arrays & objects by ref: instance method call --- 163array(1) { 164 [0]=> 165 string(12) "Ref1 changed" 166} 167array(1) { 168 [0]=> 169 array(1) { 170 [1]=> 171 string(12) "Ref2 changed" 172 } 173} 174object(stdClass)#%d (1) { 175 ["a"]=> 176 string(12) "Ref3 changed" 177} 178object(stdClass)#%d (1) { 179 ["a"]=> 180 object(stdClass)#%d (1) { 181 ["b"]=> 182 string(12) "Ref4 changed" 183 } 184} 185object(stdClass)#%d (1) { 186 ["a"]=> 187 object(stdClass)#%d (1) { 188 ["b"]=> 189 object(stdClass)#%d (1) { 190 ["c"]=> 191 string(12) "Ref5 changed" 192 } 193 } 194} 195