1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
--TEST--
Invalid containers with offsets
--FILE--
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc';
$containers = [
//false,
true,
4,
5.5,
STDERR,
//new stdClass(),
];
ob_start();
foreach ($containers as $container) {
$containerStr = get_zend_debug_type($container);
$EXPECTED_OUTPUT = <<<OUTPUT
Read before write:
Warning: Trying to access array offset on $containerStr in %s on line 8
NULL
Write:
Cannot use a scalar value as an array
Read:
Warning: Trying to access array offset on $containerStr in %s on line 22
NULL
Read-Write:
Cannot use a scalar value as an array
isset():
bool(false)
empty():
bool(true)
null coalesce:
string(7) "default"
Reference to dimension:
Cannot use a scalar value as an array
unset():
Cannot unset offset in a non-array variable
Nested read:
Warning: Trying to access array offset on $containerStr in %s on line 74
Warning: Trying to access array offset on null in %s on line 74
NULL
Nested write:
Cannot use a scalar value as an array
Nested Read-Write:
Cannot use a scalar value as an array
Nested isset():
bool(false)
Nested empty():
bool(true)
Nested null coalesce:
string(7) "default"
Nested unset():
Cannot unset offset in a non-array variable
OUTPUT;
foreach ($offsets as $dimension) {
$error = $containerStr . '[' . zend_test_var_export($dimension) . '] has different outputs' . "\n";
include $var_dim_filename;
$varOutput = ob_get_contents();
ob_clean();
$varOutput = str_replace(
[$var_dim_filename],
['%s'],
$varOutput
);
if ($EXPECTED_OUTPUT !== $varOutput) {
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_invalid_container_{$failuresNb}.txt", $varOutput);
++$failuresNb;
$failures[] = $error;
}
++$testCasesTotal;
}
/* Using offsets as references */
foreach ($offsets as $offset) {
$dimension = &$offset;
$error = $containerStr . '[&' . zend_test_var_export($dimension) . '] has different outputs' . "\n";
include $var_dim_filename;
$varOutput = ob_get_contents();
ob_clean();
$varOutput = str_replace(
[$var_dim_filename],
['%s'],
$varOutput
);
if ($EXPECTED_OUTPUT !== $varOutput) {
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_invalid_container_{$failuresNb}.txt", $varOutput);
++$failuresNb;
$failures[] = $error;
}
++$testCasesTotal;
}
}
ob_end_clean();
echo "Executed tests\n";
if ($failures !== []) {
echo "Failures:\n" . implode($failures);
}
?>
--EXPECT--
Executed tests
|