1--TEST-- 2object containers behaviour with offsets 3--FILE-- 4<?php 5 6require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc'; 7 8const EXPECTED_OUTPUT = <<<OUTPUT 9Read before write: 10Cannot use object of type stdClass as array 11Write: 12Cannot use object of type stdClass as array 13Read: 14Cannot use object of type stdClass as array 15Read-Write: 16Cannot use object of type stdClass as array 17isset(): 18Cannot use object of type stdClass as array 19empty(): 20Cannot use object of type stdClass as array 21null coalesce: 22Cannot use object of type stdClass as array 23Reference to dimension: 24Cannot use object of type stdClass as array 25unset(): 26Cannot use object of type stdClass as array 27Nested read: 28Cannot use object of type stdClass as array 29Nested write: 30Cannot use object of type stdClass as array 31Nested Read-Write: 32Cannot use object of type stdClass as array 33Nested isset(): 34Cannot use object of type stdClass as array 35Nested empty(): 36Cannot use object of type stdClass as array 37Nested null coalesce: 38Cannot use object of type stdClass as array 39Nested unset(): 40Cannot use object of type stdClass as array 41 42OUTPUT; 43 44ob_start(); 45foreach ($offsets as $dimension) { 46 $container = new stdClass(); 47 $error = '(new stdClass())[' . zend_test_var_export($dimension) . '] has different outputs' . "\n"; 48 49 include $var_dim_filename; 50 $varOutput = ob_get_contents(); 51 ob_clean(); 52 $varOutput = str_replace( 53 [$var_dim_filename], 54 ['%s'], 55 $varOutput 56 ); 57 58 if ($varOutput !== EXPECTED_OUTPUT) { 59 file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_object_container_{$failuresNb}.txt", $varOutput); 60 ++$failuresNb; 61 $failures[] = $error; 62 } 63 ++$testCasesTotal; 64} 65/* Using offsets as references */ 66foreach ($offsets as $offset) { 67 $dimension = &$offset; 68 $container = new stdClass(); 69 $error = '(new stdClass())[&' . zend_test_var_export($offset) . '] has different outputs' . "\n"; 70 71 include $var_dim_filename; 72 $varOutput = ob_get_contents(); 73 ob_clean(); 74 $varOutput = str_replace( 75 [$var_dim_filename], 76 ['%s'], 77 $varOutput 78 ); 79 80 if ($varOutput !== EXPECTED_OUTPUT) { 81 file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_object_container_{$failuresNb}.txt", $varOutput); 82 ++$failuresNb; 83 $failures[] = $error; 84 } 85 ++$testCasesTotal; 86} 87ob_end_clean(); 88 89echo "Executed tests\n"; 90if ($failures !== []) { 91 echo "Failures:\n" . implode($failures); 92} 93 94?> 95--EXPECT-- 96Executed tests 97