xref: /PHP-8.1/Zend/tests/enum/enum-as-params.phpt (revision 269c8dac)
1--TEST--
2Enum types as parameters
3--FILE--
4<?php
5
6enum Foo {
7    case Bar;
8}
9
10enum Baz {
11    case Qux;
12}
13
14function takesFoo(Foo $foo) {}
15function takesBaz(Baz $baz) {}
16
17takesFoo(Foo::Bar);
18takesBaz(Baz::Qux);
19
20try {
21    takesBaz(Foo::Bar);
22} catch (Error $e) {
23    echo $e->getMessage() . "\n";
24}
25
26try {
27    takesFoo(Baz::Qux);
28} catch (Error $e) {
29    echo $e->getMessage() . "\n";
30}
31
32?>
33--EXPECTF--
34takesBaz(): Argument #1 ($baz) must be of type Baz, Foo given, called in %s on line %d
35takesFoo(): Argument #1 ($foo) must be of type Foo, Baz given, called in %s on line %d
36