Skip to content

Commit 15a0c3a

Browse files
committed
Fix failed assertion when promoting Serialize deprecation to exception
Fixes GH-15907 Closes GH-15951
1 parent c259c9f commit 15a0c3a

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PHP NEWS
66
. Fixed bug GH-15712: zend_strtod overflow with precision INI set on
77
large value. (David Carlier)
88
. Fixed bug GH-15905 (Assertion failure for TRACK_VARS_SERVER). (cmb)
9+
. Fixed bug GH-15907 (Failed assertion when promoting Serialize deprecation to
10+
exception). (ilutov)
911

1012
- Date:
1113
. Fixed bug GH-15582: Crash when not calling parent constructor of

Zend/tests/gh15907.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-15907: Failed assertion when promoting inheritance error to exception
3+
--FILE--
4+
<?php
5+
6+
set_error_handler(function($errno, $msg) {
7+
throw new Exception($msg);
8+
});
9+
10+
class C implements Serializable {
11+
public function serialize() {}
12+
public function unserialize($serialized) {}
13+
}
14+
15+
?>
16+
--EXPECTF--
17+
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
18+
%a

Zend/zend_interfaces.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ static int zend_implement_serializable(zend_class_entry *interface, zend_class_e
473473
if (!(class_type->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)
474474
&& (!class_type->__serialize || !class_type->__unserialize)) {
475475
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));
476+
if (EG(exception)) {
477+
zend_exception_uncaught_error(
478+
"During inheritance of %s, while implementing Serializable", ZSTR_VAL(class_type->name));
479+
}
476480
}
477481
return SUCCESS;
478482
}

0 commit comments

Comments
 (0)