File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
Zend/tests/type_declarations/literal_types Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments