php-src/Zend/tests/unset_non_array.phpt
Kamil Tekiela 052af90b86 Deprecate autovivification on false
Deprecate automatically converting "false" into an empty array
on write operands. Autovivification continues to be supported
for "null" values, as well as undefined/uninitialized values.

RFC: https://wiki.php.net/rfc/autovivification_false

Closes GH-7131.

Co-authored-by: Tyson Andre <tysonandre775@hotmail.com>
Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-07-19 14:49:37 +02:00

114 lines
1.8 KiB
PHP

--TEST--
Unset on non-array
--FILE--
<?php
unset($x[0]);
$x = null;
unset($x[0]);
$x = false;
unset($x[0]);
$x = true;
try {
unset($x[0]);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
$x = 1;
try {
unset($x[0]);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
$x = 3.14;
try {
unset($x[0]);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
$x = "str";
try {
unset($x[0]);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
$x = new stdClass;
try {
unset($x[0]);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
// And now repeat the same with a nested offset.
unset($x);
unset($x[0][0]);
$x = null;
unset($x[0][0]);
$x = false;
unset($x[0][0]);
$x = true;
try {
unset($x[0][0]);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
$x = 1;
try {
unset($x[0][0]);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
$x = 3.14;
try {
unset($x[0][0]);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
$x = "str";
try {
unset($x[0][0]);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
$x = new stdClass;
try {
unset($x[0][0]);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
Warning: Undefined variable $x in %s on line %d
Deprecated: Automatic conversion of false to array is deprecated in %s
Cannot unset offset in a non-array variable
Cannot unset offset in a non-array variable
Cannot unset offset in a non-array variable
Cannot unset string offsets
Cannot use object of type stdClass as array
Warning: Undefined variable $x in %s on line %d
Deprecated: Automatic conversion of false to array is deprecated in %s
Cannot unset offset in a non-array variable
Cannot unset offset in a non-array variable
Cannot unset offset in a non-array variable
Cannot unset string offsets
Cannot use object of type stdClass as array