Boolean Used As Array¶
Booleans, true
and false
are not an array, but it is possible to use the array syntax with it. The values are then always null
, and since PHP 7.4, a warning is emitted.
PHP code¶
<?php
// var_dump(true[0]); is not a valid PHP syntax
const MY_CONSTANT = true;
var_dump(MY_CONSTANT[0]);
?>
Before¶
NULL
After¶
PHP Warning: Trying to access array offset on true in /codes/nullAsArray.php on line 3
Warning: Trying to access array offset on null in /codes/nullAsArray.php on line 3
PHP
PHP version change¶
This behavior changed in 7.4