1--TEST-- 2ArrayObject 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 ArrayObject 124Write: 125Cannot access offset of type %s on ArrayObject 126Read: 127Cannot access offset of type %s on ArrayObject 128Read-Write: 129Cannot access offset of type %s on ArrayObject 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 in isset or empty 136unset(): 137Cannot unset offset of type %s on ArrayObject 138Nested read: 139Cannot access offset of type %s on ArrayObject 140Nested write: 141Cannot access offset of type %s on ArrayObject 142Nested Read-Write: 143Cannot access offset of type %s on ArrayObject 144Nested isset(): 145Cannot access offset of type %s in isset or empty 146Nested empty(): 147Cannot access offset of type %s in isset or empty 148Nested null coalesce: 149Cannot access offset of type %s in isset or empty 150Nested unset(): 151 152Notice: Indirect modification of overloaded element of ArrayObject has no effect in %s on line 102 153Cannot unset offset of type %s on ArrayObject 154 155OUTPUT; 156 157$EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS) . '$/s'; 158 159const EXPECTED_OUTPUT_NULL_OFFSET = <<<OUTPUT 160Read before write: 161 162Warning: Undefined array key "" in %s on line 8 163NULL 164Write: 165Read: 166 167Warning: Undefined array key "" in %s on line 22 168NULL 169Read-Write: 170 171Warning: Undefined array key "" in %s on line 29 172isset(): 173bool(false) 174empty(): 175bool(true) 176null coalesce: 177string(7) "default" 178unset(): 179Nested read: 180 181Warning: Undefined array key "" in %s on line 62 182 183Warning: Trying to access array offset on null in %s on line 62 184NULL 185Nested write: 186Nested Read-Write: 187Nested isset(): 188bool(true) 189Nested empty(): 190bool(false) 191Nested null coalesce: 192int(30) 193Nested unset(): 194 195OUTPUT; 196 197const EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS = <<<OUTPUT 198Read before write: 199 200Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 8 201 202Warning: Undefined array key 3 in %s on line 8 203NULL 204Write: 205 206Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 15 207Read: 208 209Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 22 210int(5) 211Read-Write: 212 213Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 29 214 215Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 29 216isset(): 217 218Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 36 219bool(true) 220empty(): 221 222Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 42 223bool(false) 224null coalesce: 225 226Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 48 227int(25) 228unset(): 229 230Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 55 231Nested read: 232 233Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 62 234 235Warning: Undefined array key 3 in %s on line 62 236 237Warning: Trying to access array offset on null in %s on line 62 238NULL 239Nested write: 240 241Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 69 242 243Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 69 244Nested Read-Write: 245 246Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 76 247 248Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 76 249Nested isset(): 250 251Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 83 252 253Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 83 254bool(true) 255Nested empty(): 256 257Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 89 258 259Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 89 260bool(false) 261Nested null coalesce: 262 263Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95 264 265Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95 266int(30) 267Nested unset(): 268 269Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 102 270 271Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 102 272 273OUTPUT; 274 275ob_start(); 276foreach ($offsets as $dimension) { 277 $container = new ArrayObject(); 278 $error = '(new ArrayObject())[' . zend_test_var_export($dimension) . '] has different outputs' . "\n"; 279 ob_start(); 280 var_dump($dimension); 281 $var_dump_output = ob_get_clean(); 282 283 include $var_dim_filename; 284 $varOutput = ob_get_contents(); 285 ob_clean(); 286 $varOutput = str_replace( 287 [$var_dim_filename], 288 ['%s'], 289 $varOutput 290 ); 291 292 if ( 293 !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput) 294 && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput) 295 && !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput) 296 && $varOutput !== EXPECTED_OUTPUT_NULL_OFFSET 297 && $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS 298 ) { 299 file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_ArrayObject_container_{$failuresNb}.txt", $varOutput); 300 ++$failuresNb; 301 $failures[] = $error; 302 } 303 ++$testCasesTotal; 304} 305ob_end_clean(); 306 307echo "Executed tests\n"; 308if ($failures !== []) { 309 echo "Failures:\n" . implode($failures); 310} 311 312?> 313--EXPECT-- 314Executed tests 315