Skip to content

Commit 8740b58

Browse files
author
michael19
committed
#17725 change tests & change comparing instance of while checking ability to replace static with self
1 parent 2f4bbcb commit 8740b58

5 files changed

+10
-146
lines changed

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

Lines changed: 6 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,131 +5,52 @@ Overriding static return types with self in final class with union types
55

66
interface A
77
{
8-
public function methodScalar1(): static|bool;
9-
public function methodScalar2(): static|bool;
10-
public function methodScalar3(): static|false;
11-
public function methodScalar4(): static|true;
12-
public function methodScalar5(): static|bool;
13-
public function methodScalar6(): static|bool;
14-
public function methodScalar7(): static|string;
15-
public function methodScalar8(): static|string;
16-
public function methodScalar9(): static|string;
17-
public function methodScalar10(): static|int;
18-
public function methodScalar11(): static|int;
19-
public function methodScalar12(): static|int;
20-
public function methodScalar13(): static|float;
21-
public function methodScalar14(): static|float;
22-
public function methodScalar15(): static|float;
8+
public function methodScalar(): static|string;
239
public function methodIterable1(): static|iterable;
24-
public function methodIterable2(): static|iterable;
25-
public function methodIterable3(): static|array;
10+
public function methodIterable2(): static|array;
2611
public function methodObject1(): static|A;
2712
public function methodObject2(): static|B;
2813
public function methodObject3(): static|C;
2914
public function methodObject4(): static|self;
30-
public function methodObject5(): static|self;
3115
public function methodNullable1(): ?static;
32-
public function methodNullable2(): ?static;
33-
public function methodNullable3(): static|null;
34-
public function methodNullable4(): static|null;
35-
public function methodNullable5(): null;
16+
public function methodNullable2(): static|null;
3617
}
3718

3819
final class B implements A
3920
{
40-
public function methodScalar1(): self|false { return $this; }
41-
public function methodScalar2(): self|true { return $this; }
42-
public function methodScalar3(): false { return false; }
43-
public function methodScalar4(): true { return true; }
44-
public function methodScalar5(): bool { return false; }
45-
public function methodScalar6(): self { return $this; }
46-
public function methodScalar7(): self|string { return $this; }
47-
public function methodScalar8(): string { return ''; }
48-
public function methodScalar9(): self { return $this; }
21+
public function methodScalar(): self { return $this; }
4922
public function methodScalar10(): self|int { return $this; }
50-
public function methodScalar11(): int { return 0; }
51-
public function methodScalar12(): self { return $this; }
52-
public function methodScalar13(): self|float { return $this; }
53-
public function methodScalar14(): float { return 0.0; }
5423
public function methodScalar15(): self { return $this; }
5524
public function methodIterable1(): self|iterable { return $this; }
56-
public function methodIterable2(): self|array { return $this; }
57-
public function methodIterable3(): array { return []; }
25+
public function methodIterable2(): array { return []; }
5826
public function methodObject1(): self { return $this; }
5927
public function methodObject2(): B { return $this; }
6028
public function methodObject3(): C { return new C(); }
6129
public function methodObject4(): self { return $this; }
62-
public function methodObject5(): B { return $this; }
6330
public function methodNullable1(): ?static { return $this; }
6431
public function methodNullable2(): ?static { return null; }
65-
public function methodNullable3(): static|null { return null; }
66-
public function methodNullable4(): static|null { return $this; }
67-
public function methodNullable5(): null { return null; }
6832
}
6933

7034
class C
7135
{
7236
}
7337

7438
$b = new B();
75-
var_dump($b->methodScalar1());
76-
var_dump($b->methodScalar2());
77-
var_dump($b->methodScalar3());
78-
var_dump($b->methodScalar4());
79-
var_dump($b->methodScalar5());
80-
var_dump($b->methodScalar6());
81-
var_dump($b->methodScalar7());
82-
var_dump($b->methodScalar8());
83-
var_dump($b->methodScalar9());
84-
var_dump($b->methodScalar10());
85-
var_dump($b->methodScalar11());
86-
var_dump($b->methodScalar12());
87-
var_dump($b->methodScalar13());
88-
var_dump($b->methodScalar14());
89-
var_dump($b->methodScalar15());
39+
var_dump($b->methodScalar());
9040
var_dump($b->methodIterable1());
9141
var_dump($b->methodIterable2());
92-
var_dump($b->methodIterable3());
9342
var_dump($b->methodObject1());
9443
var_dump($b->methodObject2());
9544
var_dump($b->methodObject3());
9645
var_dump($b->methodObject4());
97-
var_dump($b->methodObject5());
9846
var_dump($b->methodNullable1());
9947
var_dump($b->methodNullable2());
100-
var_dump($b->methodNullable3());
101-
var_dump($b->methodNullable4());
102-
var_dump($b->methodNullable5());
10348
?>
10449
--EXPECTF--
10550
object(B)#1 (0) {
10651
}
10752
object(B)#1 (0) {
10853
}
109-
bool(false)
110-
bool(true)
111-
bool(false)
112-
object(B)#1 (0) {
113-
}
114-
object(B)#1 (0) {
115-
}
116-
string(0) ""
117-
object(B)#1 (0) {
118-
}
119-
object(B)#1 (0) {
120-
}
121-
int(0)
122-
object(B)#1 (0) {
123-
}
124-
object(B)#1 (0) {
125-
}
126-
float(0)
127-
object(B)#1 (0) {
128-
}
129-
object(B)#1 (0) {
130-
}
131-
object(B)#1 (0) {
132-
}
13354
array(0) {
13455
}
13556
object(B)#1 (0) {
@@ -142,10 +63,4 @@ object(B)#1 (0) {
14263
}
14364
object(B)#1 (0) {
14465
}
145-
object(B)#1 (0) {
146-
}
147-
NULL
148-
NULL
149-
object(B)#1 (0) {
150-
}
15166
NULL

Zend/tests/type_declarations/variance/override_static_with_self/override_static_type_with_self_in_non_final_class_with_interface.phpt renamed to Zend/tests/type_declarations/variance/override_static_with_self/override_static_type_with_self_in_non_final_class.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Overriding static return types with self in non-final class with interface
2+
Overriding static return types with self in non-final class
33
--FILE--
44
<?php
55

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

Lines changed: 0 additions & 24 deletions
This file was deleted.

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

Lines changed: 0 additions & 26 deletions
This file was deleted.

Zend/zend_inheritance.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,12 @@ static inheritance_status zend_is_class_subtype_of_type(
573573
return INHERITANCE_UNRESOLVED;
574574
}
575575

576-
// replacing static with self in final classes is okay
576+
/* Replacing static with self in final classes is okay */
577577
if (!is_intersection && (fe_scope->ce_flags & ZEND_ACC_FINAL) &&
578-
(proto_type_full_mask & MAY_BE_STATIC) && instanceof_function(fe_scope, proto_scope)) {
578+
(proto_type_full_mask & MAY_BE_STATIC) && unlinked_instanceof(fe_scope, proto_scope)) {
579579
if (!fe_ce) fe_ce = lookup_class(fe_scope, fe_class_name);
580580

581-
if (fe_ce && instanceof_function(fe_ce, fe_scope)) {
581+
if (fe_ce == fe_scope) {
582582
return INHERITANCE_SUCCESS;
583583
}
584584

@@ -692,7 +692,6 @@ ZEND_API inheritance_status zend_perform_covariant_type_check(
692692
uint32_t fe_type_mask = ZEND_TYPE_PURE_MASK(fe_type);
693693
uint32_t proto_type_mask = ZEND_TYPE_PURE_MASK(proto_type);
694694
uint32_t added_types = fe_type_mask & ~proto_type_mask;
695-
696695
if (added_types) {
697696
if ((added_types & MAY_BE_STATIC)
698697
&& zend_type_permits_self(proto_type, proto_scope, fe_scope)) {

0 commit comments

Comments
 (0)