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