File tree Expand file tree Collapse file tree 5 files changed +81
-0
lines changed
Expand file tree Collapse file tree 5 files changed +81
-0
lines changed Original file line number Diff line number Diff line change 1+ --TEST--
2+ Description: returned type does not match the type declaration
3+
4+ --FILE--
5+ <?php
6+
7+ function get_config (): array {
8+ return 42 ;
9+ }
10+
11+
12+ --EXPECTF --
13+ Fatal error: the function get_config was expected to return an array and returned an integer in %s on line 4
14+
15+
16+
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Int is not a valid type declaration
3+
4+ --FILE--
5+ <?php
6+
7+ function answer (): int {
8+ return 42 ;
9+ }
10+
11+ --EXPECTF --
12+ Fatal error: the function answer was expected to return an object of class int and returned an integer in %s on line 4
13+
14+
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Cannot return null with a return type declaration
3+
4+ --FILE--
5+ <?php
6+
7+ function foo (): bar {
8+ return null ;
9+ }
10+
11+ --EXPECTF --
12+ Fatal error: the function foo was expected to return an object of class bar and returned null in %s on line 4
13+
14+
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Missing return type on override
3+
4+ --FILE--
5+ <?php
6+
7+ class User {}
8+
9+ interface UserGateway {
10+ function find ($ id ) : User ;
11+ }
12+
13+ class UserGateway_MySql implements UserGateway {
14+ // must return User or subtype of User
15+ function find ($ id ) {
16+ return new User ;
17+ }
18+ }
19+
20+ --EXPECTF --
21+ Fatal error: Delcaration of UserGateway_MySql::find should be compatible with UserGateway::find ($ id ) : User, return type missing in %s on line 9
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Cannot define a return type on a Generator
3+
4+ --FILE--
5+ <?php
6+
7+ function filter (Traversable $ in , callable $ filter ): array {
8+ foreach ($ in as $ key => $ value ) {
9+ if ($ filter ($ key , $ value )) {
10+ yield $ key => $ value ;
11+ }
12+ }
13+ }
14+
15+ --EXPECTF --
16+ Fatal error: The "yield " expression can not be used inside a function with a return type hint in %s on line 6
You can’t perform that action at this time.
0 commit comments