Skip to content

Commit 1bc5bd7

Browse files
committed
Handle both WARNING and UNRESOLVED during early binding
We would previously early exit on the WARNING, and miss the later UNRESOLVED.
1 parent c2b2930 commit 1bc5bd7

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Check that both warning and unresolved during early binding is handled
3+
--FILE--
4+
<?php
5+
class Test extends SplObjectStorage {
6+
function valid() {}
7+
function current(): Unknown {}
8+
}
9+
?>
10+
--EXPECTF--
11+
Deprecated: Return type of Test::valid() should either be compatible with SplObjectStorage::valid(): bool, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in %s on line %d
12+
13+
Fatal error: Could not check compatibility between Test::current(): Unknown and SplObjectStorage::current(): object, because class Unknown is not available in %s on line %d

Zend/zend_inheritance.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3004,6 +3004,7 @@ static inheritance_status zend_can_early_bind(zend_class_entry *ce, zend_class_e
30043004
zend_string *key;
30053005
zend_function *parent_func;
30063006
zend_property_info *parent_info;
3007+
inheritance_status overall_status = INHERITANCE_SUCCESS;
30073008

30083009
ZEND_HASH_FOREACH_STR_KEY_PTR(&parent_ce->function_table, key, parent_func) {
30093010
zval *zv = zend_hash_find_ex(&ce->function_table, key, 1);
@@ -3014,8 +3015,9 @@ static inheritance_status zend_can_early_bind(zend_class_entry *ce, zend_class_e
30143015
child_func, child_func->common.scope,
30153016
parent_func, parent_func->common.scope,
30163017
ce, NULL, /* check_visibility */ 1, 1, 0);
3017-
3018-
if (UNEXPECTED(status != INHERITANCE_SUCCESS)) {
3018+
if (UNEXPECTED(status == INHERITANCE_WARNING)) {
3019+
overall_status = INHERITANCE_WARNING;
3020+
} else if (UNEXPECTED(status != INHERITANCE_SUCCESS)) {
30193021
return status;
30203022
}
30213023
}
@@ -3032,14 +3034,15 @@ static inheritance_status zend_can_early_bind(zend_class_entry *ce, zend_class_e
30323034
zend_property_info *child_info = Z_PTR_P(zv);
30333035
if (ZEND_TYPE_IS_SET(child_info->type)) {
30343036
inheritance_status status = property_types_compatible(parent_info, child_info);
3037+
ZEND_ASSERT(status != INHERITANCE_WARNING);
30353038
if (UNEXPECTED(status != INHERITANCE_SUCCESS)) {
30363039
return status;
30373040
}
30383041
}
30393042
}
30403043
} ZEND_HASH_FOREACH_END();
30413044

3042-
return INHERITANCE_SUCCESS;
3045+
return overall_status;
30433046
}
30443047
/* }}} */
30453048

0 commit comments

Comments
 (0)