Skip to content

Commit f1c6357

Browse files
authored
Deprecate making __debugInfo() nullable (#21984)
* Deprecate making `__debugInfo()` nullable Returning `null` is already deprecated since PHP 8.5 (3dc962b). Not deprecating a corresponding return type seems like an oversight. * NEWS / UPGRADING
1 parent 3ed80a1 commit f1c6357

8 files changed

Lines changed: 27 additions & 5 deletions

File tree

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PHP NEWS
1818
initialization). (Arnaud)
1919
. Enabled the TAILCALL VM on Windows when compiling with Clang >= 19 x86_64.
2020
(henderkes)
21+
. Deprecate specifying a nullable return type for __debugInfo(). (timwolla)
2122

2223
- BCMath:
2324
. Added NUL-byte validation to BCMath functions. (jorgsowa)

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ PHP 8.6 UPGRADE NOTES
189189
4. Deprecated Functionality
190190
========================================
191191

192+
- Core:
193+
. Specifying a return type of array|null / ?array for __debugInfo() is now
194+
deprecated. Specify array instead.
195+
192196
- GMP
193197
. The shift (<<, >>) and exponentiation (**) operators on GMP objects now
194198
emit a deprecation warning when converting a float right operand to int

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)