PHP code example of fpoirotte / enum-trait
1. Go to this page and download the library: Download fpoirotte/enum-trait library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fpoirotte / enum-trait example snippets
use \fpoirotte\EnumTrait;
final class FavoriteColor implements Serializable
{
use EnumTrait;
private $RED;
private $BLUE;
private $GREEN;
}
$red = FavoriteColor::RED();
$red2 = FavoriteColor::RED();
$red3 = unserialize(serialize($red));
$red4 = clone $red;
$blue = FavoriteColor::BLUE();
// Compare two distinct values
var_dump($red == $blue); // False
// Compare various instances of the same value
var_dump($red == $red2); // True
var_dump($red == $red3); // True
var_dump($red == $red4); // True
// Get the enum's value name
var_dump((string) $red); // "RED"
function displayUsingFavoriteColor(FavoriteColor $color, $message) {
// ...
}
class MyEnum extends SomeInferiorEnum
{
const VALUE1 = 'value1';
}