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 58 ---- Pass uninitialised array & object by ref: function call --- 59array(1) { 60 [0]=> 61 string(12) "Ref1 changed" 62} 63array(1) { 64 [0]=> 65 array(1) { 66 [1]=> 67 string(12) "Ref2 changed" 68 } 69} 70object(stdClass)#%d (1) { 71 ["a"]=> 72 string(12) "Ref3 changed" 73} 74object(stdClass)#%d (1) { 75 ["a"]=> 76 object(stdClass)#%d (1) { 77 ["b"]=> 78 string(12) "Ref4 changed" 79 } 80} 81object(stdClass)#%d (1) { 82 ["a"]=> 83 object(stdClass)#%d (1) { 84 ["b"]=> 85 object(stdClass)#%d (1) { 86 ["c"]=> 87 string(12) "Ref5 changed" 88 } 89 } 90} 91 92 ---- Pass uninitialised arrays & objects by ref: static method call --- 93 94Deprecated: Non-static method C::refs() should not be called statically in %s on line 39 95array(1) { 96 [0]=> 97 string(12) "Ref1 changed" 98} 99array(1) { 100 [0]=> 101 array(1) { 102 [1]=> 103 string(12) "Ref2 changed" 104 } 105} 106object(stdClass)#%d (1) { 107 ["a"]=> 108 string(12) "Ref3 changed" 109} 110object(stdClass)#%d (1) { 111 ["a"]=> 112 object(stdClass)#%d (1) { 113 ["b"]=> 114 string(12) "Ref4 changed" 115 } 116} 117object(stdClass)#%d (1) { 118 ["a"]=> 119 object(stdClass)#%d (1) { 120 ["b"]=> 121 object(stdClass)#%d (1) { 122 ["c"]=> 123 string(12) "Ref5 changed" 124 } 125 } 126} 127 128 129---- Pass uninitialised arrays & objects by ref: constructor --- 130array(1) { 131 [0]=> 132 string(12) "Ref1 changed" 133} 134array(1) { 135 [0]=> 136 array(1) { 137 [1]=> 138 string(12) "Ref2 changed" 139 } 140} 141object(stdClass)#%d (1) { 142 ["a"]=> 143 string(12) "Ref3 changed" 144} 145object(stdClass)#%d (1) { 146 ["a"]=> 147 object(stdClass)#%d (1) { 148 ["b"]=> 149 string(12) "Ref4 changed" 150 } 151} 152object(stdClass)#%d (1) { 153 ["a"]=> 154 object(stdClass)#%d (1) { 155 ["b"]=> 156 object(stdClass)#%d (1) { 157 ["c"]=> 158 string(12) "Ref5 changed" 159 } 160 } 161} 162 163 ---- Pass uninitialised arrays & objects by ref: instance method call --- 164array(1) { 165 [0]=> 166 string(12) "Ref1 changed" 167} 168array(1) { 169 [0]=> 170 array(1) { 171 [1]=> 172 string(12) "Ref2 changed" 173 } 174} 175object(stdClass)#%d (1) { 176 ["a"]=> 177 string(12) "Ref3 changed" 178} 179object(stdClass)#%d (1) { 180 ["a"]=> 181 object(stdClass)#%d (1) { 182 ["b"]=> 183 string(12) "Ref4 changed" 184 } 185} 186object(stdClass)#%d (1) { 187 ["a"]=> 188 object(stdClass)#%d (1) { 189 ["b"]=> 190 object(stdClass)#%d (1) { 191 ["c"]=> 192 string(12) "Ref5 changed" 193 } 194 } 195} 196