Commit 4ae7f913df3 for php
commit 4ae7f913df31509c5314f7e3d4c05d558a58b534
Author: Arnaud Le Blanc <365207+arnaud-lb@users.noreply.github.com>
Date: Fri Nov 20 20:04:56 2026 +0100
Do not fatal when __debugInfo() returns and invalid type (#25624)
diff --git a/Zend/tests/debug_info/debug_info-error-0.0.phpt b/Zend/tests/debug_info/debug_info-error-0.0.phpt
index 4df25c4c95a..fa48a6a4318 100644
--- a/Zend/tests/debug_info/debug_info-error-0.0.phpt
+++ b/Zend/tests/debug_info/debug_info-error-0.0.phpt
@@ -14,7 +14,13 @@ public function __construct($val) {
}
$c = new C(0.0);
-var_dump($c);
+try {
+ var_dump($c);
+} catch(TypeError $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-Fatal error: __debugInfo() must return an array in %s on line %d
+object(C)#%d (0) {
+}
+TypeError: C::__debugInfo() must return an array, float returned
diff --git a/Zend/tests/debug_info/debug_info-error-0.phpt b/Zend/tests/debug_info/debug_info-error-0.phpt
index c0cedf3b88e..c50262aca69 100644
--- a/Zend/tests/debug_info/debug_info-error-0.phpt
+++ b/Zend/tests/debug_info/debug_info-error-0.phpt
@@ -14,7 +14,13 @@ public function __construct($val) {
}
$c = new C(0);
-var_dump($c);
+try {
+ var_dump($c);
+} catch(TypeError $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-Fatal error: __debugInfo() must return an array in %s on line %d
+object(C)#%d (0) {
+}
+TypeError: C::__debugInfo() must return an array, int returned
diff --git a/Zend/tests/debug_info/debug_info-error-1.0.phpt b/Zend/tests/debug_info/debug_info-error-1.0.phpt
index 6af945cb0e3..9bdaace3989 100644
--- a/Zend/tests/debug_info/debug_info-error-1.0.phpt
+++ b/Zend/tests/debug_info/debug_info-error-1.0.phpt
@@ -14,7 +14,13 @@ public function __construct($val) {
}
$c = new C(1.0);
-var_dump($c);
+try {
+ var_dump($c);
+} catch(TypeError $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-Fatal error: __debugInfo() must return an array in %s on line %d
+object(C)#%d (0) {
+}
+TypeError: C::__debugInfo() must return an array, float returned
diff --git a/Zend/tests/debug_info/debug_info-error-1.phpt b/Zend/tests/debug_info/debug_info-error-1.phpt
index 7cadd485118..407278d362a 100644
--- a/Zend/tests/debug_info/debug_info-error-1.phpt
+++ b/Zend/tests/debug_info/debug_info-error-1.phpt
@@ -14,7 +14,13 @@ public function __construct($val) {
}
$c = new C(1);
-var_dump($c);
+try {
+ var_dump($c);
+} catch(TypeError $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-Fatal error: __debugInfo() must return an array in %s on line %d
+object(C)#%d (0) {
+}
+TypeError: C::__debugInfo() must return an array, int returned
diff --git a/Zend/tests/debug_info/debug_info-error-case-insensitive.phpt b/Zend/tests/debug_info/debug_info-error-case-insensitive.phpt
index c2a6f4357a5..71bb8dcff5e 100644
--- a/Zend/tests/debug_info/debug_info-error-case-insensitive.phpt
+++ b/Zend/tests/debug_info/debug_info-error-case-insensitive.phpt
@@ -14,7 +14,13 @@ public function __construct($val) {
}
$c = new C(1);
-var_dump($c);
+try {
+ var_dump($c);
+} catch(TypeError $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-Fatal error: __debugInfo() must return an array in %s on line %d
+object(C)#%d (0) {
+}
+TypeError: C::__debugInfo() must return an array, int returned
diff --git a/Zend/tests/debug_info/debug_info-error-empty_str.phpt b/Zend/tests/debug_info/debug_info-error-empty_str.phpt
index 21611cc9bde..d73e01ba824 100644
--- a/Zend/tests/debug_info/debug_info-error-empty_str.phpt
+++ b/Zend/tests/debug_info/debug_info-error-empty_str.phpt
@@ -14,7 +14,13 @@ public function __construct($val) {
}
$c = new C("");
-var_dump($c);
+try {
+ var_dump($c);
+} catch(TypeError $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-Fatal error: __debugInfo() must return an array in %s on line %d
+object(C)#%d (0) {
+}
+TypeError: C::__debugInfo() must return an array, string returned
diff --git a/Zend/tests/debug_info/debug_info-error-false.phpt b/Zend/tests/debug_info/debug_info-error-false.phpt
index fb5a35c2d1e..6c829a4222e 100644
--- a/Zend/tests/debug_info/debug_info-error-false.phpt
+++ b/Zend/tests/debug_info/debug_info-error-false.phpt
@@ -14,7 +14,13 @@ public function __construct($val) {
}
$c = new C(false);
-var_dump($c);
+try {
+ var_dump($c);
+} catch(TypeError $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-Fatal error: __debugInfo() must return an array in %s on line %d
+object(C)#%d (0) {
+}
+TypeError: C::__debugInfo() must return an array, false returned
diff --git a/Zend/tests/debug_info/debug_info-error-object.phpt b/Zend/tests/debug_info/debug_info-error-object.phpt
index 5cdc6b289e6..37a96efca49 100644
--- a/Zend/tests/debug_info/debug_info-error-object.phpt
+++ b/Zend/tests/debug_info/debug_info-error-object.phpt
@@ -14,7 +14,13 @@ public function __construct($val) {
}
$c = new C(new stdClass);
-var_dump($c);
+try {
+ var_dump($c);
+} catch(TypeError $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-Fatal error: __debugInfo() must return an array in %s on line %d
+object(C)#%d (0) {
+}
+TypeError: C::__debugInfo() must return an array, stdClass returned
diff --git a/Zend/tests/debug_info/debug_info-error-pre-exception.phpt b/Zend/tests/debug_info/debug_info-error-pre-exception.phpt
new file mode 100644
index 00000000000..c2fbe84c4e9
--- /dev/null
+++ b/Zend/tests/debug_info/debug_info-error-pre-exception.phpt
@@ -0,0 +1,27 @@
+--TEST--
+__debugInfo() with pre-existing exception does not emit a duplicate exception
+--FILE--
+<?php
+
+class C {
+ public $val;
+ public function __debugInfo() {
+ return $this->val;
+ }
+ public function __construct($val) {
+ $this->val = $val;
+ }
+}
+
+try {
+ var_dump(new C(0), new C(['test' => 0]));
+} catch(TypeError $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
+?>
+--EXPECTF--
+object(C)#%d (0) {
+}
+object(C)#%d (0) {
+}
+TypeError: C::__debugInfo() must return an array, int returned
diff --git a/Zend/tests/debug_info/debug_info-error-resource.phpt b/Zend/tests/debug_info/debug_info-error-resource.phpt
index 1fc84fe83d8..0004bf40543 100644
--- a/Zend/tests/debug_info/debug_info-error-resource.phpt
+++ b/Zend/tests/debug_info/debug_info-error-resource.phpt
@@ -16,7 +16,13 @@ public function __construct($val) {
}
$c = new C(fopen("data:text/plain,Foo", 'r'));
-var_dump($c);
+try {
+ var_dump($c);
+} catch(TypeError $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-Fatal error: __debugInfo() must return an array in %s on line %d
+object(C)#%d (0) {
+}
+TypeError: C::__debugInfo() must return an array, resource returned
diff --git a/Zend/tests/debug_info/debug_info-error-str.phpt b/Zend/tests/debug_info/debug_info-error-str.phpt
index fe4201de1c9..5a808220c22 100644
--- a/Zend/tests/debug_info/debug_info-error-str.phpt
+++ b/Zend/tests/debug_info/debug_info-error-str.phpt
@@ -14,7 +14,13 @@ public function __construct($val) {
}
$c = new C("foo");
-var_dump($c);
+try {
+ var_dump($c);
+} catch(TypeError $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-Fatal error: __debugInfo() must return an array in %s on line %d
+object(C)#%d (0) {
+}
+TypeError: C::__debugInfo() must return an array, string returned
diff --git a/Zend/tests/debug_info/debug_info-error-true.phpt b/Zend/tests/debug_info/debug_info-error-true.phpt
index 12bb7329a85..b82376e0e89 100644
--- a/Zend/tests/debug_info/debug_info-error-true.phpt
+++ b/Zend/tests/debug_info/debug_info-error-true.phpt
@@ -14,7 +14,13 @@ public function __construct($val) {
}
$c = new C(true);
-var_dump($c);
+try {
+ var_dump($c);
+} catch(TypeError $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-Fatal error: __debugInfo() must return an array in %s on line %d
+object(C)#%d (0) {
+}
+TypeError: C::__debugInfo() must return an array, true returned
diff --git a/Zend/tests/fibers/get-return-after-bailout.phpt b/Zend/tests/fibers/get-return-after-bailout.phpt
index 01bf1364ec5..44ab9b17054 100644
--- a/Zend/tests/fibers/get-return-after-bailout.phpt
+++ b/Zend/tests/fibers/get-return-after-bailout.phpt
@@ -1,5 +1,7 @@
--TEST--
Fiber::getReturn() after bailout
+--EXTENSIONS--
+zend_test
--FILE--
<?php
@@ -9,13 +11,13 @@
});
$fiber = new Fiber(static function (): void {
- var_dump(new class { public function __debugInfo() { return ''; } }); // cause a bailout
+ var_dump(zend_trigger_bailout());
});
$fiber->start();
?>
--EXPECTF--
-Fatal error: __debugInfo() must return an array in %s on line %d
+Fatal error: Bailout in %s on line %d
Fatal error: Uncaught FiberError: Cannot get fiber return value: The fiber exited with a fatal error in %sget-return-after-bailout.php:%d
Stack trace:
diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c
index c88e2e06199..90f8c841b47 100644
--- a/Zend/zend_object_handlers.c
+++ b/Zend/zend_object_handlers.c
@@ -206,6 +206,12 @@ ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp) /
return object->handlers->get_properties(object);
}
+ if (EG(exception)) {
+ /* Method call will fail */
+ *is_temp = 1;
+ return zend_new_array(0);
+ }
+
zend_call_known_instance_method_with_0_params(ce->__debugInfo, object, &retval);
if (UNEXPECTED(Z_ISREF(retval))) {
zend_unwrap_reference(&retval);
@@ -231,7 +237,11 @@ ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp) /
return ht;
}
- zend_error_noreturn(E_ERROR, ZEND_DEBUGINFO_FUNC_NAME "() must return an array");
+ zend_type_error("%pS::__debugInfo() must return an array, %s returned", ce->name, zend_zval_value_name(&retval));
+ zval_ptr_dtor(&retval);
+
+ *is_temp = 1;
+ return zend_new_array(0);
}
/* }}} */
diff --git a/ext/zend_test/tests/observer_bug81430_2.phpt b/ext/zend_test/tests/observer_bug81430_2.phpt
index 918794d6ea1..592a12a4985 100644
--- a/ext/zend_test/tests/observer_bug81430_2.phpt
+++ b/ext/zend_test/tests/observer_bug81430_2.phpt
@@ -12,7 +12,7 @@
#[\Attribute]
class A {
public function __construct() {
- var_dump(new class { public function __debugInfo() { return ''; } }); // cause a bailout
+ var_dump(zend_trigger_bailout());
}
}
@@ -35,14 +35,11 @@ function B() {}
<ReflectionAttribute::newInstance>
<!-- init A::__construct() -->
<A::__construct>
- <!-- init var_dump() -->
- <var_dump>
- <!-- init class@anonymous::__debugInfo() -->
- <class@anonymous::__debugInfo>
- </class@anonymous::__debugInfo>
+ <!-- init zend_trigger_bailout() -->
+ <zend_trigger_bailout>
-Fatal error: __debugInfo() must return an array in %s on line %d
- </var_dump>
+Fatal error: Bailout in %s on line %d
+ </zend_trigger_bailout>
</A::__construct>
</ReflectionAttribute::newInstance>
</file '%s'>
diff --git a/ext/zend_test/tests/observer_bug81435.phpt b/ext/zend_test/tests/observer_bug81435.phpt
index 54f3f1fb82b..d7c002b3752 100644
--- a/ext/zend_test/tests/observer_bug81435.phpt
+++ b/ext/zend_test/tests/observer_bug81435.phpt
@@ -21,7 +21,7 @@ function b() {
}
function bailout(...$args) {
- var_dump(new class { public function __debugInfo() { return ''; } }); // cause a bailout
+ var_dump(zend_trigger_bailout());
}
function a() { // observed (first_observed_frame)
@@ -42,8 +42,7 @@ function a() { // observed (first_observed_frame)
<d>
</d>
<!-- init bailout() -->
- <!-- init var_dump() -->
- <!-- init class@anonymous::__debugInfo() -->
+ <!-- init zend_trigger_bailout() -->
-Fatal error: __debugInfo() must return an array in %s on line %d
+Fatal error: Bailout in %s on line %d
</a>
diff --git a/ext/zend_test/tests/observer_error_01.phpt b/ext/zend_test/tests/observer_error_01.phpt
index da9fcf9b757..45edad8711d 100644
--- a/ext/zend_test/tests/observer_error_01.phpt
+++ b/ext/zend_test/tests/observer_error_01.phpt
@@ -11,7 +11,7 @@
<?php
function foo()
{
- var_dump(new class { public function __debugInfo() { return ''; } }); // cause a bailout
+ var_dump(zend_trigger_bailout());
}
foo();
@@ -23,13 +23,10 @@ function foo()
<file '%s'>
<!-- init foo() -->
<foo>
- <!-- init var_dump() -->
- <var_dump>
- <!-- init class@anonymous::__debugInfo() -->
- <class@anonymous::__debugInfo>
- </class@anonymous::__debugInfo:''>
+ <!-- init zend_trigger_bailout() -->
+ <zend_trigger_bailout>
-Fatal error: __debugInfo() must return an array in %s on line %d
- </var_dump:NULL>
+Fatal error: Bailout in %s on line %d
+ </zend_trigger_bailout:NULL>
</foo:NULL>
</file '%s%eobserver_error_%d.php'>
diff --git a/ext/zend_test/tests/observer_fiber_functions_03.phpt b/ext/zend_test/tests/observer_fiber_functions_03.phpt
index 8b9d5fa20c1..639d70d86c6 100644
--- a/ext/zend_test/tests/observer_fiber_functions_03.phpt
+++ b/ext/zend_test/tests/observer_fiber_functions_03.phpt
@@ -22,7 +22,7 @@
$fiber = new Fiber(function (): void {
var_dump(2);
Fiber::suspend();
- var_dump(new class { public function __debugInfo() { return ''; } }); // cause a bailout
+ var_dump(zend_trigger_bailout());
});
$fiber->start();
@@ -71,13 +71,11 @@
<!-- switching from fiber %s to %s -->
<resume '%s'>
</Fiber::suspend>
- <var_dump>
- <!-- init class@anonymous::__debugInfo() -->
- <class@anonymous::__debugInfo>
- </class@anonymous::__debugInfo>
+ <!-- init zend_trigger_bailout() -->
+ <zend_trigger_bailout>
-Fatal error: __debugInfo() must return an array in %s on line %d
- </var_dump>
+Fatal error: Bailout in %s on line %d
+ </zend_trigger_bailout>
</{closure:%s:%d}>
<!-- switching from fiber %s to %s -->
<returned '%s'>