BackedEnum::from
BackedEnum::from
Maps a scalar to an enum instance
static **BackedEnum::from** $value
The method translates a or
into the corresponding Enum case, if any. If there is no matching case defined, it will throw
a .
from``string``int``ValueError
valueThe scalar value to map to an enum case.
A case instance of this enumeration.
Voorbeeld: Basic usage
The following example illustrates how enum cases are returned.
<?php
enum Suit: string
{
case Hearts = 'H';
case Diamonds = 'D';
case Clubs = 'C';
case Spades = 'S';
}
$h = Suit::from('H');
var_dump($h);
$b = Suit::from('B');
?>
enum(Suit::Hearts)
Fatal error: Uncaught ValueError: "B" is not a valid backing value for enum "Suit" in /file.php:15
UnitEnum::cases``BackedEnum::tryFrom