Skip to content

Commit 343ae96

Browse files
committed
Add test describing overloading behaviour
1 parent 57c628f commit 343ae96

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
No coercion should be applied to type false even if it's an overloading
3+
--FILE--
4+
<?php
5+
6+
class P {
7+
public function foo($v): array|bool {
8+
return $v;
9+
}
10+
}
11+
12+
class C {
13+
public function foo($v): array|false {
14+
return $v;
15+
}
16+
}
17+
18+
$p = new P();
19+
$c = new C();
20+
21+
var_dump($p->foo(0));
22+
try {
23+
var_dump($c->foo(0));
24+
} catch (\TypeError $e) {
25+
echo $e->getMessage(), \PHP_EOL;
26+
}
27+
28+
?>
29+
--EXPECT--
30+
bool(false)
31+
C::foo(): Return value must be of type array|false, int returned
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
No coercion should be applied to type true even if it's an overloading
3+
--FILE--
4+
<?php
5+
6+
class P {
7+
public function foo($v): array|bool {
8+
return $v;
9+
}
10+
}
11+
12+
class C {
13+
public function foo($v): array|true {
14+
return $v;
15+
}
16+
}
17+
18+
$p = new P();
19+
$c = new C();
20+
21+
var_dump($p->foo(1));
22+
try {
23+
var_dump($c->foo(1));
24+
} catch (\TypeError $e) {
25+
echo $e->getMessage(), \PHP_EOL;
26+
}
27+
28+
?>
29+
--EXPECT--
30+
bool(true)
31+
C::foo(): Return value must be of type array|true, int returned

0 commit comments

Comments
 (0)