PHP code example of warengo / enum
1. Go to this page and download the library: Download warengo/enum 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/ */
warengo / enum example snippets
/**
* @method static self ENGLAND()
* @method static self USA()
*/
class CountryEnum extends Enum
{
protected static function getEnums(): array
{
return ['england', 'usa'];
}
}
assert(CountryEnum::USA() === CountryEnum::USA());
function country(CountryEnum $country): string {
return $country->value();
}
assert(country(CountryEnum::USA()) === 'usa');
assert(CountryEnum::get('usa') === CountryEnum::USA());