1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00
Files
archived-php-src/ext/reflection/tests/ReflectionEnumBackedCase_getBackingValue.phpt
Ilija Tovilo 269c8dac1d Implement enums
RFC: https://wiki.php.net/rfc/enumerations

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>

Closes GH-6489.
2021-03-17 19:08:03 +01:00

39 lines
809 B
PHP

--TEST--
ReflectionEnumBackedCase::getBackingValue()
--FILE--
<?php
enum Enum_ {
case Foo;
}
enum IntEnum: int {
case Foo = 0;
}
enum StringEnum: string {
case Foo = 'Foo';
}
try {
var_dump(new ReflectionEnumBackedCase(Enum_::class, 'Foo'));
} catch (ReflectionException $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(new ReflectionEnumBackedCase([], 'Foo'));
} catch (Error $e) {
echo $e->getMessage() . "\n";
}
var_dump((new ReflectionEnumBackedCase(IntEnum::class, 'Foo'))->getBackingValue());
var_dump((new ReflectionEnumBackedCase(StringEnum::class, 'Foo'))->getBackingValue());
?>
--EXPECT--
Enum case Enum_::Foo is not a backed case
ReflectionEnumBackedCase::__construct(): Argument #1 ($class) must be of type object|string, array given
int(0)
string(3) "Foo"