Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3c5fc0b

Browse filesBrowse files
committed
Tests
1 parent 1164585 commit 3c5fc0b
Copy full SHA for 3c5fc0b

File tree

Expand file treeCollapse file tree

4 files changed

+59
-28
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+59
-28
lines changed
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Intersection types and typed reference
3+
--FILE--
4+
<?php
5+
6+
interface X {}
7+
interface Y {}
8+
interface Z {}
9+
10+
class A implements X, Y, Z {}
11+
class B implements X, Y {}
12+
13+
class Test {
14+
public X&Y $y;
15+
public X&Z $z;
16+
}
17+
$test = new Test;
18+
$r = new A;
19+
$test->y =& $r;
20+
$test->z =& $r;
21+
22+
try {
23+
$r = new B;
24+
} catch (\TypeError $e) {
25+
echo $e->getMessage(), \PHP_EOL;
26+
}
27+
28+
?>
29+
--EXPECT--
30+
Cannot assign B to reference held by property Test::$z of type X&Z

‎Zend/tests/type_declarations/intersection_types/variance/valid1.phpt

Copy file name to clipboardExpand all lines: Zend/tests/type_declarations/intersection_types/variance/valid1.phpt
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Basic tests for intersection types
2+
Valid inheritence - co-variance
33
--FILE--
44
<?php
55

+9-27Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,22 @@
11
--TEST--
2-
Intersection with a child type is valid
2+
Commutative intersection types
33
--FILE--
44
<?php
55

66
interface A {}
7-
interface B extends A{}
8-
interface C {}
9-
10-
class Test implements A, B {}
7+
interface B {}
118

129
class Foo {
13-
public function foo(): A&B {
14-
return new Test();
15-
}
10+
public A&B $prop;
11+
public function foo(A&B $v): A&B {}
1612
}
1713

1814
class FooChild extends Foo {
19-
public function foo(): A&B {
20-
return new Test();
21-
}
22-
}
23-
24-
class FooChildAgain extends Foo {
25-
public function foo(): B&A {
26-
return new Test();
27-
}
15+
public B&A $prop;
16+
public function foo(B&A $v): B&A {}
2817
}
2918

30-
$o = new FooChild();
31-
var_dump($o->foo());
32-
$o = new FooChildAgain();
33-
var_dump($o->foo());
34-
3519
?>
36-
--EXPECTF--
37-
object(Test)#%d (0) {
38-
}
39-
object(Test)#%d (0) {
40-
}
20+
===DONE===
21+
--EXPECT--
22+
===DONE===
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Intersection type reduction invariant type check
3+
--FILE--
4+
<?php
5+
6+
class A {}
7+
class B extends A {}
8+
9+
class Test {
10+
public A&B $prop;
11+
}
12+
class Test2 extends Test {
13+
public B $prop;
14+
}
15+
16+
?>
17+
===DONE===
18+
--EXPECT--
19+
===DONE===

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.