1--TEST-- 2String 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: Uninitialized string offset %d in %s on line 8 12string(0) "" 13Write: 14Read: 15string(1) "5" 16Read-Write: 17Cannot use assign-op operators with string offsets 18isset(): 19bool(true) 20empty(): 21bool(false) 22null coalesce: 23string(1) "5" 24unset(): 25Cannot unset string offsets 26Nested read: 27 28Warning: Uninitialized string offset %d in %s on line 62 29string(0) "" 30Nested write: 31Cannot use string offset as an array 32Nested Read-Write: 33Cannot use string offset as an array 34Nested isset(): 35bool(false) 36Nested empty(): 37bool(true) 38Nested null coalesce: 39string(7) "default" 40Nested unset(): 41Cannot use string offset as an array 42 43OUTPUT; 44 45$EXPECTED_OUTPUT_VALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_VALID_OFFSETS) . '$/s'; 46 47const EXPECTED_OUTPUT_VALID_OFFSETS_OUT_OF_RANGE = <<<OUTPUT 48Read before write: 49 50Warning: Uninitialized string offset %i in %s on line 8 51string(0) "" 52Write: 53 54Warning: Illegal string offset %i in %s on line 15 55Read: 56 57Warning: Uninitialized string offset %i in %s on line 22 58string(0) "" 59Read-Write: 60Cannot use assign-op operators with string offsets 61isset(): 62bool(false) 63empty(): 64bool(true) 65null coalesce: 66string(7) "default" 67unset(): 68Cannot unset string offsets 69Nested read: 70 71Warning: Uninitialized string offset %i in %s on line 62 72 73Warning: Uninitialized string offset %i in %s on line 62 74string(0) "" 75Nested write: 76Cannot use string offset as an array 77Nested Read-Write: 78Cannot use string offset as an array 79Nested isset(): 80bool(false) 81Nested empty(): 82bool(true) 83Nested null coalesce: 84string(7) "default" 85Nested unset(): 86Cannot use string offset as an array 87 88OUTPUT; 89 90$EXPECTED_OUTPUT_VALID_OFFSETS_OUT_OF_RANGE_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_VALID_OFFSETS_OUT_OF_RANGE) . '$/s'; 91 92const EXPECTED_OUTPUT_STRING_CAST_OFFSETS = <<<OUTPUT 93Read before write: 94 95Warning: String offset cast occurred in %s on line 8 96 97Warning: Uninitialized string offset %d in %s on line 8 98string(0) "" 99Write: 100 101Warning: String offset cast occurred in %s on line 15 102Read: 103 104Warning: String offset cast occurred in %s on line 22 105string(1) "5" 106Read-Write: 107 108Warning: String offset cast occurred in %s on line 29 109Cannot use assign-op operators with string offsets 110isset(): 111bool(true) 112empty(): 113bool(false) 114null coalesce: 115string(1) "5" 116unset(): 117Cannot unset string offsets 118Nested read: 119 120Warning: String offset cast occurred in %s on line 62 121 122Warning: String offset cast occurred in %s on line 62 123 124Warning: Uninitialized string offset %d in %s on line 62 125string(0) "" 126Nested write: 127 128Warning: String offset cast occurred in %s on line 69 129Cannot use string offset as an array 130Nested Read-Write: 131 132Warning: String offset cast occurred in %s on line 76 133Cannot use string offset as an array 134Nested isset(): 135bool(false) 136Nested empty(): 137bool(true) 138Nested null coalesce: 139string(7) "default" 140Nested unset(): 141 142Warning: String offset cast occurred in %s on line 102 143Cannot use string offset as an array 144 145OUTPUT; 146 147$EXPECTED_OUTPUT_STRING_CAST_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_STRING_CAST_OFFSETS) . '$/s'; 148 149const EXPECTED_OUTPUT_STRING_CAST_OFFSETS_TO_0 = <<<OUTPUT 150Read before write: 151 152Warning: String offset cast occurred in %s on line 8 153 154Warning: Uninitialized string offset 0 in %s on line 8 155string(0) "" 156Write: 157 158Warning: String offset cast occurred in %s on line 15 159Read: 160 161Warning: String offset cast occurred in %s on line 22 162string(1) "5" 163Read-Write: 164 165Warning: String offset cast occurred in %s on line 29 166Cannot use assign-op operators with string offsets 167isset(): 168bool(true) 169empty(): 170bool(false) 171null coalesce: 172string(1) "5" 173unset(): 174Cannot unset string offsets 175Nested read: 176 177Warning: String offset cast occurred in %s on line 62 178 179Warning: String offset cast occurred in %s on line 62 180string(1) "5" 181Nested write: 182 183Warning: String offset cast occurred in %s on line 69 184Cannot use string offset as an array 185Nested Read-Write: 186 187Warning: String offset cast occurred in %s on line 76 188Cannot use string offset as an array 189Nested isset(): 190bool(true) 191Nested empty(): 192bool(false) 193Nested null coalesce: 194string(1) "5" 195Nested unset(): 196 197Warning: String offset cast occurred in %s on line 102 198Cannot use string offset as an array 199 200OUTPUT; 201 202$EXPECTED_OUTPUT_STRING_CAST_OFFSETS_TO_0_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_STRING_CAST_OFFSETS_TO_0) . '$/s'; 203 204const EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE = <<<OUTPUT 205Read before write: 206 207Warning: String offset cast occurred in %s on line 8 208 209Warning: Uninitialized string offset %i in %s on line 8 210string(0) "" 211Write: 212 213Warning: String offset cast occurred in %s on line 15 214 215Warning: Illegal string offset %i in %s on line 15 216Read: 217 218Warning: String offset cast occurred in %s on line 22 219 220Warning: Uninitialized string offset %i in %s on line 22 221string(0) "" 222Read-Write: 223 224Warning: String offset cast occurred in %s on line 29 225Cannot use assign-op operators with string offsets 226isset(): 227bool(false) 228empty(): 229bool(true) 230null coalesce: 231string(7) "default" 232unset(): 233Cannot unset string offsets 234Nested read: 235 236Warning: String offset cast occurred in %s on line 62 237 238Warning: Uninitialized string offset %i in %s on line 62 239 240Warning: String offset cast occurred in %s on line 62 241 242Warning: Uninitialized string offset %i in %s on line 62 243string(0) "" 244Nested write: 245 246Warning: String offset cast occurred in %s on line 69 247Cannot use string offset as an array 248Nested Read-Write: 249 250Warning: String offset cast occurred in %s on line 76 251Cannot use string offset as an array 252Nested isset(): 253bool(false) 254Nested empty(): 255bool(true) 256Nested null coalesce: 257string(7) "default" 258Nested unset(): 259 260Warning: String offset cast occurred in %s on line 102 261Cannot use string offset as an array 262 263OUTPUT; 264 265$EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE) . '$/s'; 266 267const EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE = <<<OUTPUT 268Read before write: 269 270Warning: String offset cast occurred in %s on line 8 271 272Warning: Uninitialized string offset %i in %s on line 8 273string(0) "" 274Write: 275 276Warning: String offset cast occurred in %s on line 15 277 278Warning: Illegal string offset %i in %s on line 15 279Read: 280 281Warning: String offset cast occurred in %s on line 22 282 283Warning: Uninitialized string offset %i in %s on line 22 284string(0) "" 285Read-Write: 286 287Warning: String offset cast occurred in %s on line 29 288Cannot use assign-op operators with string offsets 289isset(): 290 291Deprecated: Implicit conversion from float %f to int loses precision in %s on line 36 292bool(false) 293empty(): 294 295Deprecated: Implicit conversion from float %f to int loses precision in %s on line 42 296bool(true) 297null coalesce: 298string(7) "default" 299unset(): 300Cannot unset string offsets 301Nested read: 302 303Warning: String offset cast occurred in %s on line 62 304 305Warning: Uninitialized string offset %i in %s on line 62 306 307Warning: String offset cast occurred in %s on line 62 308 309Warning: Uninitialized string offset %i in %s on line 62 310string(0) "" 311Nested write: 312 313Warning: String offset cast occurred in %s on line 69 314Cannot use string offset as an array 315Nested Read-Write: 316 317Warning: String offset cast occurred in %s on line 76 318Cannot use string offset as an array 319Nested isset(): 320bool(false) 321Nested empty(): 322bool(true) 323Nested null coalesce: 324string(7) "default" 325Nested unset(): 326 327Warning: String offset cast occurred in %s on line 102 328Cannot use string offset as an array 329 330OUTPUT; 331 332$EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE) . '$/s'; 333 334const EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS = <<<OUTPUT 335Read before write: 336 337Warning: String offset cast occurred in %s on line 8 338 339Warning: Uninitialized string offset %d in %s on line 8 340string(0) "" 341Write: 342 343Warning: String offset cast occurred in %s on line 15 344Read: 345 346Warning: String offset cast occurred in %s on line 22 347string(1) "5" 348Read-Write: 349 350Warning: String offset cast occurred in %s on line 29 351Cannot use assign-op operators with string offsets 352isset(): 353 354Deprecated: Implicit conversion from float %F to int loses precision in %s on line 36 355bool(true) 356empty(): 357 358Deprecated: Implicit conversion from float %F to int loses precision in %s on line 42 359bool(false) 360null coalesce: 361string(1) "5" 362unset(): 363Cannot unset string offsets 364Nested read: 365 366Warning: String offset cast occurred in %s on line 62 367 368Warning: String offset cast occurred in %s on line 62 369string(1) "5" 370Nested write: 371 372Warning: String offset cast occurred in %s on line 69 373Cannot use string offset as an array 374Nested Read-Write: 375 376Warning: String offset cast occurred in %s on line 76 377Cannot use string offset as an array 378Nested isset(): 379 380Deprecated: Implicit conversion from float %F to int loses precision in %s on line 83 381bool(true) 382Nested empty(): 383 384Deprecated: Implicit conversion from float %F to int loses precision in %s on line 89 385bool(false) 386Nested null coalesce: 387string(1) "5" 388Nested unset(): 389 390Warning: String offset cast occurred in %s on line 102 391Cannot use string offset as an array 392 393OUTPUT; 394 395$EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS) . '$/s'; 396 397const EXPECTED_OUTPUT_INVALID_OFFSETS = <<<OUTPUT 398Read before write: 399Cannot access offset of type %s on string 400Write: 401Cannot access offset of type %s on string 402Read: 403Cannot access offset of type %s on string 404Read-Write: 405Cannot access offset of type %s on string 406isset(): 407bool(false) 408empty(): 409bool(true) 410null coalesce: 411Cannot access offset of type %s on string 412unset(): 413Cannot unset string offsets 414Nested read: 415Cannot access offset of type %s on string 416Nested write: 417Cannot access offset of type %s on string 418Nested Read-Write: 419Cannot access offset of type %s on string 420Nested isset(): 421Cannot access offset of type %s on string 422Nested empty(): 423Cannot access offset of type %s on string 424Nested null coalesce: 425Cannot access offset of type %s on string 426Nested unset(): 427Cannot unset string offsets 428 429OUTPUT; 430 431$EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS) . '$/s'; 432 433const EXPECTED_OUTPUT_INVALID_OFFSETS_AS_STRINGS = <<<OUTPUT 434Read before write: 435Cannot access offset of type string on string 436Write: 437Cannot access offset of type string on string 438Read: 439Cannot access offset of type string on string 440Read-Write: 441Cannot access offset of type string on string 442isset(): 443bool(false) 444empty(): 445bool(true) 446null coalesce: 447string(7) "default" 448unset(): 449Cannot unset string offsets 450Nested read: 451Cannot access offset of type string on string 452Nested write: 453Cannot access offset of type string on string 454Nested Read-Write: 455Cannot access offset of type string on string 456Nested isset(): 457bool(false) 458Nested empty(): 459bool(true) 460Nested null coalesce: 461string(7) "default" 462Nested unset(): 463Cannot unset string offsets 464 465OUTPUT; 466 467const EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS = <<<OUTPUT 468Read before write: 469 470Warning: Illegal string offset %s in %s on line 8 471 472Warning: Uninitialized string offset %d in %s on line 8 473string(0) "" 474Write: 475 476Warning: Illegal string offset %s in %s on line 15 477Read: 478 479Warning: Illegal string offset %s in %s on line 22 480string(1) "5" 481Read-Write: 482 483Warning: Illegal string offset %s in %s on line 29 484Cannot use assign-op operators with string offsets 485isset(): 486bool(false) 487empty(): 488bool(true) 489null coalesce: 490 491Warning: Illegal string offset %s in %s on line 48 492string(1) "5" 493unset(): 494Cannot unset string offsets 495Nested read: 496 497Warning: Illegal string offset %s in %s on line 62 498 499Warning: Illegal string offset %s in %s on line 62 500 501Warning: Uninitialized string offset %d in %s on line 62 502string(0) "" 503Nested write: 504 505Warning: Illegal string offset %s in %s on line 69 506Cannot use string offset as an array 507Nested Read-Write: 508 509Warning: Illegal string offset %s in %s on line 76 510Cannot use string offset as an array 511Nested isset(): 512 513Warning: Illegal string offset %s in %s on line 83 514bool(false) 515Nested empty(): 516 517Warning: Illegal string offset %s in %s on line 89 518bool(true) 519Nested null coalesce: 520 521Warning: Illegal string offset %s in %s on line 95 522 523Warning: Illegal string offset %s in %s on line 95 524string(7) "default" 525Nested unset(): 526Cannot use string offset as an array 527 528OUTPUT; 529 530$EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS) . '$/s'; 531 532const EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_TO_0 = <<<OUTPUT 533Read before write: 534 535Warning: Illegal string offset %s in %s on line 8 536 537Warning: Uninitialized string offset 0 in %s on line 8 538string(0) "" 539Write: 540 541Warning: Illegal string offset %s in %s on line 15 542Read: 543 544Warning: Illegal string offset %s in %s on line 22 545string(1) "5" 546Read-Write: 547 548Warning: Illegal string offset %s in %s on line 29 549Cannot use assign-op operators with string offsets 550isset(): 551bool(false) 552empty(): 553bool(true) 554null coalesce: 555 556Warning: Illegal string offset %s in %s on line 48 557string(1) "5" 558unset(): 559Cannot unset string offsets 560Nested read: 561 562Warning: Illegal string offset %s in %s on line 62 563 564Warning: Illegal string offset %s in %s on line 62 565string(1) "5" 566Nested write: 567 568Warning: Illegal string offset %s in %s on line 69 569Cannot use string offset as an array 570Nested Read-Write: 571 572Warning: Illegal string offset %s in %s on line 76 573Cannot use string offset as an array 574Nested isset(): 575 576Warning: Illegal string offset %s in %s on line 83 577bool(false) 578Nested empty(): 579 580Warning: Illegal string offset %s in %s on line 89 581bool(true) 582Nested null coalesce: 583 584Warning: Illegal string offset %s in %s on line 95 585 586Warning: Illegal string offset %s in %s on line 95 587string(1) "5" 588Nested unset(): 589Cannot use string offset as an array 590 591OUTPUT; 592 593$EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_TO_0_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_TO_0) . '$/s'; 594 595ob_start(); 596foreach ($offsets as $dimension) { 597 $container = ''; 598 $error = '""[' . zend_test_var_export($dimension) . '] has different outputs' . "\n"; 599 600 include $var_dim_filename; 601 $varOutput = ob_get_contents(); 602 ob_clean(); 603 $varOutput = str_replace( 604 [$var_dim_filename], 605 ['%s'], 606 $varOutput 607 ); 608 609 if ( 610 !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput) 611 && !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput) 612 && !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_REGEX, $varOutput) 613 && !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_TO_0_REGEX, $varOutput) 614 && !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput) 615 && !preg_match($EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput) 616 && !preg_match($EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS_REGEX, $varOutput) 617 && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput) 618 && $varOutput !== EXPECTED_OUTPUT_INVALID_OFFSETS_AS_STRINGS 619 && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_REGEX, $varOutput) 620 && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_TO_0_REGEX, $varOutput) 621 ) { 622 file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_string_container_{$failuresNb}.txt", $varOutput); 623 ++$failuresNb; 624 $failures[] = $error; 625 } 626 ++$testCasesTotal; 627} 628ob_end_clean(); 629 630echo "Executed tests\n"; 631if ($failures !== []) { 632 echo "Failures:\n" . implode($failures); 633} 634 635?> 636--EXPECT-- 637Executed tests 638