mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00

RFC: https://wiki.php.net/rfc/enumerations Co-authored-by: Nikita Popov <nikita.ppv@gmail.com> Closes GH-6489.
35 lines
575 B
PHP
35 lines
575 B
PHP
--TEST--
|
|
Enum types as parameters
|
|
--FILE--
|
|
<?php
|
|
|
|
enum Foo {
|
|
case Bar;
|
|
}
|
|
|
|
enum Baz {
|
|
case Qux;
|
|
}
|
|
|
|
function takesFoo(Foo $foo) {}
|
|
function takesBaz(Baz $baz) {}
|
|
|
|
takesFoo(Foo::Bar);
|
|
takesBaz(Baz::Qux);
|
|
|
|
try {
|
|
takesBaz(Foo::Bar);
|
|
} catch (Error $e) {
|
|
echo $e->getMessage() . "\n";
|
|
}
|
|
|
|
try {
|
|
takesFoo(Baz::Qux);
|
|
} catch (Error $e) {
|
|
echo $e->getMessage() . "\n";
|
|
}
|
|
|
|
?>
|
|
--EXPECTF--
|
|
takesBaz(): Argument #1 ($baz) must be of type Baz, Foo given, called in %s on line %d
|
|
takesFoo(): Argument #1 ($foo) must be of type Foo, Baz given, called in %s on line %d
|