1--TEST-- 2array containers behaviour with offsets 3--FILE-- 4<?php 5 6require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc'; 7 8const EXPECTED_OUTPUT_VALID_OFFSETS = <<<OUTPUT 9Read before write: 10 11Warning: Undefined array key %s in %s on line 8 12NULL 13Write: 14Read: 15int(5) 16Read-Write: 17isset(): 18bool(true) 19empty(): 20bool(false) 21null coalesce: 22int(25) 23unset(): 24Nested read: 25 26Warning: Undefined array key %s in %s on line 62 27 28Warning: Trying to access array offset on null in %s on line 62 29NULL 30Nested write: 31Nested Read-Write: 32Nested isset(): 33bool(true) 34Nested empty(): 35bool(false) 36Nested null coalesce: 37int(30) 38Nested unset(): 39OUTPUT; 40 41$EXPECTED_OUTPUT_VALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_VALID_OFFSETS) . '$/s'; 42 43const EXPECTF_OUTPUT_FLOAT_OFFSETS = <<<OUTPUT 44Read before write: 45 46Deprecated: Implicit conversion from float %F to int loses precision in %s on line 8 47 48Warning: Undefined array key %s in %s on line 8 49NULL 50Write: 51 52Deprecated: Implicit conversion from float %F to int loses precision in %s on line 15 53Read: 54 55Deprecated: Implicit conversion from float %F to int loses precision in %s on line 22 56int(15) 57Read-Write: 58 59Deprecated: Implicit conversion from float %F to int loses precision in %s on line 29 60isset(): 61 62Deprecated: Implicit conversion from float %F to int loses precision in %s on line 36 63bool(true) 64empty(): 65 66Deprecated: Implicit conversion from float %F to int loses precision in %s on line 42 67bool(false) 68null coalesce: 69 70Deprecated: Implicit conversion from float %F to int loses precision in %s on line 48 71int(35) 72unset(): 73 74Deprecated: Implicit conversion from float %F to int loses precision in %s on line 55 75Nested read: 76 77Deprecated: Implicit conversion from float %F to int loses precision in %s on line 62 78 79Warning: Undefined array key 0 in %s on line 62 80 81Warning: Trying to access array offset on null in %s on line 62 82NULL 83Nested write: 84 85Deprecated: Implicit conversion from float %F to int loses precision in %s on line 69 86 87Deprecated: Implicit conversion from float %F to int loses precision in %s on line 69 88Nested Read-Write: 89 90Deprecated: Implicit conversion from float %F to int loses precision in %s on line 76 91 92Deprecated: Implicit conversion from float %F to int loses precision in %s on line 76 93Nested isset(): 94 95Deprecated: Implicit conversion from float %F to int loses precision in %s on line 83 96 97Deprecated: Implicit conversion from float %F to int loses precision in %s on line 83 98bool(true) 99Nested empty(): 100 101Deprecated: Implicit conversion from float %F to int loses precision in %s on line 89 102 103Deprecated: Implicit conversion from float %F to int loses precision in %s on line 89 104bool(false) 105Nested null coalesce: 106 107Deprecated: Implicit conversion from float %F to int loses precision in %s on line 95 108 109Deprecated: Implicit conversion from float %F to int loses precision in %s on line 95 110int(25) 111Nested unset(): 112 113Deprecated: Implicit conversion from float %F to int loses precision in %s on line 102 114 115Deprecated: Implicit conversion from float %F to int loses precision in %s on line 102 116 117OUTPUT; 118 119$EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s'; 120 121const EXPECTED_OUTPUT_INVALID_OFFSETS = <<<OUTPUT 122Read before write: 123Cannot access offset of type %s on array 124Write: 125Cannot access offset of type %s on array 126Read: 127Cannot access offset of type %s on array 128Read-Write: 129Cannot access offset of type %s on array 130isset(): 131Cannot access offset of type %s in isset or empty 132empty(): 133Cannot access offset of type %s in isset or empty 134null coalesce: 135Cannot access offset of type %s on array 136unset(): 137Cannot unset offset of type %s on array 138Nested read: 139Cannot access offset of type %s on array 140Nested write: 141Cannot access offset of type %s on array 142Nested Read-Write: 143Cannot access offset of type %s on array 144Nested isset(): 145Cannot access offset of type %s on array 146Nested empty(): 147Cannot access offset of type %s on array 148Nested null coalesce: 149Cannot access offset of type %s on array 150Nested unset(): 151Cannot access offset of type %s on array 152 153OUTPUT; 154 155$EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS) . '$/s'; 156 157const EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS = <<<OUTPUT 158Read before write: 159 160Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 8 161 162Warning: Undefined array key 3 in %s on line 8 163NULL 164Write: 165 166Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 15 167Read: 168 169Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 22 170int(5) 171Read-Write: 172 173Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 29 174isset(): 175 176Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 36 177bool(true) 178empty(): 179 180Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 42 181bool(false) 182null coalesce: 183 184Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 48 185int(25) 186unset(): 187 188Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 55 189Nested read: 190 191Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 62 192 193Warning: Undefined array key 3 in %s on line 62 194 195Warning: Trying to access array offset on null in %s on line 62 196NULL 197Nested write: 198 199Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 69 200 201Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 69 202Nested Read-Write: 203 204Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 76 205 206Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 76 207Nested isset(): 208 209Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 83 210 211Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 83 212bool(true) 213Nested empty(): 214 215Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 89 216 217Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 89 218bool(false) 219Nested null coalesce: 220 221Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95 222 223Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95 224int(30) 225Nested unset(): 226 227Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 102 228 229Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 102 230 231OUTPUT; 232 233ob_start(); 234foreach ($offsets as $dimension) { 235 $container = []; 236 $error = '[][' . zend_test_var_export($dimension) . '] has different outputs' . "\n"; 237 238 include $var_dim_filename; 239 $varOutput = ob_get_contents(); 240 ob_clean(); 241 $varOutput = str_replace( 242 [$var_dim_filename], 243 ['%s'], 244 $varOutput 245 ); 246 247 if ( 248 !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput) 249 && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput) 250 && !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput) 251 && $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS 252 ) { 253 file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_array_container_{$failuresNb}.txt", $varOutput); 254 ++$failuresNb; 255 $failures[] = $error; 256 } 257 ++$testCasesTotal; 258} 259ob_end_clean(); 260 261echo "Executed tests\n"; 262if ($failures !== []) { 263 echo "Failures:\n" . implode($failures); 264} 265 266?> 267--EXPECT-- 268Executed tests 269