Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

__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 .

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat