Skip to content

Commit 6b3ca17

Browse files
committed
#17725 change way to checking availability to replace static with self in final classes
1 parent 7fe477d commit 6b3ca17

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

Zend/tests/type_declarations/override_another_type_in_final_class_with_union_type_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ $b = new B();
1717
var_dump($b->methodScalar1());
1818
?>
1919
--EXPECTF--
20-
Fatal error: Declaration of B::methodScalar1(): array must be compatible with A::methodScalar1(): static|bool in %s on line %d
20+
Fatal error: Declaration of B::methodScalar1(): B|array must be compatible with A::methodScalar1(): static|bool in %s on line %d

Zend/zend_inheritance.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,11 @@ static inheritance_status zend_is_class_subtype_of_type(
570570
if (have_unresolved) {
571571
return INHERITANCE_UNRESOLVED;
572572
}
573+
574+
if (!is_intersection && fe_scope->ce_flags & ZEND_ACC_FINAL && instanceof_function(fe_scope, proto_scope)) {
575+
return INHERITANCE_SUCCESS;
576+
}
577+
573578
return is_intersection ? INHERITANCE_SUCCESS : INHERITANCE_ERROR;
574579
}
575580

@@ -678,13 +683,6 @@ ZEND_API inheritance_status zend_perform_covariant_type_check(
678683
uint32_t proto_type_mask = ZEND_TYPE_PURE_MASK(proto_type);
679684
uint32_t added_types = fe_type_mask & ~proto_type_mask;
680685

681-
if (proto_type_mask & MAY_BE_STATIC && fe_type_mask | MAY_BE_STATIC &&
682-
fe_scope->ce_flags & ZEND_ACC_FINAL &&
683-
instanceof_function(fe_scope, proto_scope)) {
684-
/* Replacing type that accepts static with self in final classes is okay */
685-
return INHERITANCE_SUCCESS;
686-
}
687-
688686
if (added_types) {
689687
if ((added_types & MAY_BE_STATIC)
690688
&& zend_type_permits_self(proto_type, proto_scope, fe_scope)) {

0 commit comments

Comments
 (0)