Skip to content

Commit 86a85c5

Browse files
committed
Fix Throwable implementation, again
1 parent 873acc0 commit 86a85c5

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

Zend/zend_exceptions.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,17 @@ static zend_object_handlers default_exception_handlers;
5353
/* {{{ zend_implement_throwable */
5454
static int zend_implement_throwable(zend_class_entry *interface, zend_class_entry *class_type)
5555
{
56-
/* During the registration of Exception/Error themselves, this may be called before
57-
* zend_ce_exception and zend_ce_error have been initialized, so handle these explicitly. */
58-
if (zend_ce_exception && instanceof_function(class_type, zend_ce_exception)) {
59-
return SUCCESS;
60-
}
61-
if (zend_ce_error && instanceof_function(class_type, zend_ce_error)) {
62-
return SUCCESS;
63-
}
64-
if (zend_string_equals_literal(class_type->name, "Exception")
65-
|| zend_string_equals_literal(class_type->name, "Error")) {
56+
/* zend_ce_exception and zend_ce_error may not be initialized yet when this is caleld (e.g when
57+
* implementing Throwable for Exception itself). Perform a manual inheritance check. */
58+
zend_class_entry *root = class_type;
59+
while (root->parent) {
60+
root = root->parent;
61+
}
62+
if (zend_string_equals_literal(root->name, "Exception")
63+
|| zend_string_equals_literal(root->name, "Error")) {
6664
return SUCCESS;
6765
}
66+
6867
zend_error_noreturn(E_ERROR,
6968
"Class %s cannot implement interface %s, extend Exception or Error instead",
7069
ZSTR_VAL(class_type->name),

0 commit comments

Comments
 (0)