Skip to content

Commit fb64cbf

Browse files
committed
Deprecate making __debugInfo() nullable
Returning `null` is already deprecated since PHP 8.5 (3dc962b). Not deprecating a corresponding return type seems like an oversight.
1 parent 5d7a15f commit fb64cbf

6 files changed

Lines changed: 22 additions & 5 deletions

File tree

Zend/tests/debug_info/debug_info.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ class Bar {
2121
}
2222
}
2323

24+
class Baz {
25+
public function __debugInfo(): ?array {
26+
return null;
27+
}
28+
}
29+
2430
$f = new Foo;
2531
var_dump($f);
2632

2733
$b = new Bar;
2834
var_dump($b);
2935
?>
3036
--EXPECTF--
37+
Deprecated: Returning null from Baz::__debugInfo() is deprecated, make the return type non-nullable and return an empty array instead in %s on line %d
3138
object(Foo)#%d (3) {
3239
["a"]=>
3340
int(1)

Zend/tests/magic_methods/magic_methods_inheritance_rules.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ class WidenedArgumentType extends NarrowedReturnType {
6666

6767
echo 'No problems!';
6868
?>
69-
--EXPECT--
69+
--EXPECTF--
70+
Deprecated: Returning null from ValidMagicMethods::__debugInfo() is deprecated, make the return type non-nullable and return an empty array instead in %s on line %d
7071
No problems!

Zend/tests/return_types/042.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ class JustAnArray {
2020

2121
echo 'No problems!';
2222
?>
23-
--EXPECT--
23+
--EXPECTF--
24+
Deprecated: Returning null from UnionType::__debugInfo() is deprecated, make the return type non-nullable and return an empty array instead in %s on line %d
25+
26+
Deprecated: Returning null from UnionType2::__debugInfo() is deprecated, make the return type non-nullable and return an empty array instead in %s on line %d
27+
28+
Deprecated: Returning null from UnionTypeOldStyle::__debugInfo() is deprecated, make the return type non-nullable and return an empty array instead in %s on line %d
2429
No problems!

Zend/zend_API.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,6 +2825,10 @@ ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce,
28252825
zend_check_magic_method_non_static(ce, fptr, error_type);
28262826
zend_check_magic_method_public(ce, fptr);
28272827
zend_check_magic_method_return_type(ce, fptr, error_type, (MAY_BE_ARRAY | MAY_BE_NULL));
2828+
if ((fptr->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) && ZEND_TYPE_PURE_MASK(fptr->common.arg_info[-1].type) & MAY_BE_NULL) {
2829+
zend_error(E_DEPRECATED, "Returning null from %s::__debugInfo() is deprecated, make the return type non-nullable and return an empty array instead",
2830+
ZSTR_VAL(ce->name));
2831+
}
28282832
} else if (zend_string_equals_literal(lcname, "__serialize")) {
28292833
zend_check_magic_method_args(0, ce, fptr, error_type);
28302834
zend_check_magic_method_non_static(ce, fptr, error_type);

ext/simplexml/simplexml.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getName(): string {}
5151

5252
public function __toString(): string {}
5353

54-
public function __debugInfo(): ?array {}
54+
public function __debugInfo(): array {}
5555

5656
/** @tentative-return-type */
5757
public function count(): int {}

ext/simplexml/simplexml_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)