From 15a0c3a9d4cbe9e3b54002bae9383475bc722376 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 19 Sep 2024 00:44:44 +0200 Subject: [PATCH] Fix failed assertion when promoting Serialize deprecation to exception Fixes GH-15907 Closes GH-15951 --- NEWS | 2 ++ Zend/tests/gh15907.phpt | 18 ++++++++++++++++++ Zend/zend_interfaces.c | 4 ++++ 3 files changed, 24 insertions(+) create mode 100644 Zend/tests/gh15907.phpt diff --git a/NEWS b/NEWS index 172705ecb61..b09b1ea44bd 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ PHP NEWS . Fixed bug GH-15712: zend_strtod overflow with precision INI set on large value. (David Carlier) . Fixed bug GH-15905 (Assertion failure for TRACK_VARS_SERVER). (cmb) + . Fixed bug GH-15907 (Failed assertion when promoting Serialize deprecation to + exception). (ilutov) - Date: . Fixed bug GH-15582: Crash when not calling parent constructor of diff --git a/Zend/tests/gh15907.phpt b/Zend/tests/gh15907.phpt new file mode 100644 index 00000000000..8d6dada36ad --- /dev/null +++ b/Zend/tests/gh15907.phpt @@ -0,0 +1,18 @@ +--TEST-- +GH-15907: Failed assertion when promoting inheritance error to exception +--FILE-- + +--EXPECTF-- +Fatal error: During inheritance of C, while implementing Serializable: Uncaught Exception: C implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s:%d +%a diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c index b8cc5e94cac..39d647c7e29 100644 --- a/Zend/zend_interfaces.c +++ b/Zend/zend_interfaces.c @@ -473,6 +473,10 @@ static int zend_implement_serializable(zend_class_entry *interface, zend_class_e if (!(class_type->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) && (!class_type->__serialize || !class_type->__unserialize)) { zend_error(E_DEPRECATED, "%s implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary)", ZSTR_VAL(class_type->name)); + if (EG(exception)) { + zend_exception_uncaught_error( + "During inheritance of %s, while implementing Serializable", ZSTR_VAL(class_type->name)); + } } return SUCCESS; }