__debugInfo() Nullable Return Type Is Deprecated¶
The magic method __debugInfo() used to be freely typed to return ?array, since null and array were both acceptable return values. In PHP 8.6, simply declaring __debugInfo() with a nullable ?array return type is deprecated, regardless of what is actually returned: the return type should be made non-nullable, and an empty array should be returned instead of null.
PHP code¶
<?php
class x {
public function __debugInfo(): ?array {
return ['a' => 1];
}
}
var_dump(new x());
?>
Before¶
object(x)#1 (1) {
[a]=>
int(1)
}
After¶
PHP Deprecated: Returning null from x::__debugInfo() is deprecated, make the return type non-nullable and return an empty array instead
Deprecated: Returning null from x::__debugInfo() is deprecated, make the return type non-nullable and return an empty array instead
object(x)#1 (1) {
[a]=>
int(1)
}
PHP version change¶
This behavior was deprecated in 8.6
This behavior changed in