Skip to content

Commit

Permalink
Fix failed assertion when promoting Serialize deprecation to exception
Browse files Browse the repository at this point in the history
  • Loading branch information
iluuu1994 committed Sep 18, 2024
1 parent b26e610 commit 60daeb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Zend/tests/gh15907.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
GH-15907: Failed assertion when promoting inheritance error to exception
--FILE--
<?php

set_error_handler(function($errno, $msg) {
throw new Exception($msg);
});

class C implements Serializable {
public function serialize() {}
public function unserialize($serialized) {}
}

?>
--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
4 changes: 4 additions & 0 deletions Zend/zend_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 60daeb8

Please sign in to comment.