[RFC] Deprecate returning null from __debugInfo() (#19455)

RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_debuginfo_returning_null
This commit is contained in:
Daniel Scherzer 2025-08-12 03:15:18 -07:00 committed by GitHub
parent 3d9d68e1ca
commit 3dc962b9f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 0 deletions

View file

@ -36,5 +36,7 @@ object(Foo)#%d (3) {
["c":"Foo":private]=> ["c":"Foo":private]=>
int(3) int(3)
} }
Deprecated: Returning null from Bar::__debugInfo() is deprecated, return an empty array instead in %s on line %d
object(Bar)#%d (0) { object(Bar)#%d (0) {
} }

View file

@ -0,0 +1,31 @@
--TEST--
Testing __debugInfo() magic method
--FILE--
<?php
set_error_handler(
static function () {
echo "in handler\n";
$f = new Foo();
var_dump($f);
}
);
class Foo {
public function __debugInfo() {
return null;
}
}
$f = new Foo;
var_dump($f);
?>
--EXPECTF--
in handler
Deprecated: Returning null from Foo::__debugInfo() is deprecated, return an empty array instead in %s on line %d
object(Foo)#3 (0) {
}
object(Foo)#2 (0) {
}

View file

@ -223,6 +223,8 @@ ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp) /
return Z_ARRVAL(retval); return Z_ARRVAL(retval);
} }
} else if (Z_TYPE(retval) == IS_NULL) { } else if (Z_TYPE(retval) == IS_NULL) {
zend_error(E_DEPRECATED, "Returning null from %s::__debugInfo() is deprecated, return an empty array instead",
ZSTR_VAL(ce->name));
*is_temp = 1; *is_temp = 1;
ht = zend_new_array(0); ht = zend_new_array(0);
return ht; return ht;