Skip to content

Commit 1b95868

Browse files
committed
#17725 change checking ability to replace static with self & update tests
1 parent a957dbf commit 1b95868

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

Zend/tests/type_declarations/variance/override_static_with_self/override_another_type_in_final_class_with_union_type_3.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ interface A
88
public function methodScalar1(): static|bool;
99
}
1010

11-
final class B implements A
11+
final class C implements A
1212
{
13-
public function methodScalar1(): C { return new C(); }
13+
public function methodScalar1(): self { return $this; }
1414
}
1515

16-
final class C implements A
16+
final class B implements A
1717
{
18-
public function methodScalar1(): self { return $this; }
18+
public function methodScalar1(): C { return new C(); }
1919
}
2020

2121
$b = new B();

Zend/tests/type_declarations/variance/override_static_with_self/override_another_type_in_final_class_with_union_type_4.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ interface A
88
public function methodScalar1(): static|bool;
99
}
1010

11-
final class B implements A
11+
final class C implements A
1212
{
13-
public function methodScalar1(): C|array { return []; }
13+
public function methodScalar1(): self { return $this; }
1414
}
1515

16-
final class C implements A
16+
final class B implements A
1717
{
18-
public function methodScalar1(): self { return $this; }
18+
public function methodScalar1(): C|array { return []; }
1919
}
2020

2121
$b = new B();

Zend/tests/type_declarations/variance/override_static_with_self/override_another_type_in_final_class_with_union_type_5.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ interface A
88
public function methodScalar1(): static|bool;
99
}
1010

11-
final class B implements A
11+
final class C
1212
{
13-
public function methodScalar1(): C { return new C(); }
1413
}
1514

16-
final class C
15+
final class B implements A
1716
{
17+
public function methodScalar1(): C { return new C(); }
1818
}
1919

2020
$b = new B();

Zend/tests/type_declarations/variance/override_static_with_self/override_another_type_in_final_class_with_union_type_6.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ interface A
88
public function methodScalar1(): static|bool;
99
}
1010

11-
final class B implements A
11+
final class C
1212
{
13-
public function methodScalar1(): C|array { return []; }
1413
}
1514

16-
final class C
15+
final class B implements A
1716
{
17+
public function methodScalar1(): C|array { return []; }
1818
}
1919

2020
$b = new B();

Zend/zend_inheritance.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,18 @@ static inheritance_status zend_is_class_subtype_of_type(
502502
}
503503
}
504504

505+
/* Replacing static with self in final classes is okay */
506+
if ((ZEND_TYPE_FULL_MASK(proto_type) & MAY_BE_STATIC) &&
507+
(fe_scope->ce_flags & ZEND_ACC_FINAL) && unlinked_instanceof(fe_scope, proto_scope)) {
508+
if (!fe_ce) fe_ce = lookup_class(fe_scope, fe_class_name);
509+
if (!fe_ce) {
510+
have_unresolved = 1;
511+
} else if (fe_ce == fe_scope) {
512+
track_class_dependency(fe_ce, fe_class_name);
513+
return INHERITANCE_SUCCESS;
514+
}
515+
}
516+
505517
zend_type *single_type;
506518

507519
/* Traverse the list of parent types and check if the current child (FE)
@@ -571,18 +583,6 @@ static inheritance_status zend_is_class_subtype_of_type(
571583
return INHERITANCE_UNRESOLVED;
572584
}
573585

574-
/* Replacing static with self in final classes is okay */
575-
if ((ZEND_TYPE_FULL_MASK(proto_type) & MAY_BE_STATIC) &&
576-
(fe_scope->ce_flags & ZEND_ACC_FINAL) && unlinked_instanceof(fe_scope, proto_scope)) {
577-
if (!fe_ce) fe_ce = lookup_class(fe_scope, fe_class_name);
578-
579-
if (fe_ce == fe_scope) {
580-
return INHERITANCE_SUCCESS;
581-
}
582-
583-
return INHERITANCE_ERROR;
584-
}
585-
586586
return is_intersection ? INHERITANCE_SUCCESS : INHERITANCE_ERROR;
587587
}
588588

0 commit comments

Comments
 (0)