Magic Method __debugInfo() cannot return null
__debugInfo() is a magic method that returns an array with debug information. It gives a chance to the program to return any useful information, beyond the local properties. It also allows to remove any sensitive information, such as passwords or secrets. Since PHP 8.6, it is not possible to return NULL: the method method must return an array, albeit empty.
PHP code
<?php
class x {
function __debugInfo() {
return null;
}
}
var_dump(new x);
?>
Before
object(x)#1 (0) {
}
After
PHP Deprecated: Returning null from x::__debugInfo() is deprecated, return an empty array instead in /codes/debugInfoCannotReturnNull.php on line 9
Deprecated: Returning null from x::__debugInfo() is deprecated, return an empty array instead in /codes/debugInfoCannotReturnNull.php on line 9
object(x)#1 (0) {
}
PHP version change
This behavior changed in 8.5.