1. Go to this page and download the library: Download rikudou/enums-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/ */
use rikudou\PHPEnum\EnumTrait;
class MyCoolEnum
{
use EnumTrait;
public static function EnumValue1() {
return static::_get("EnumValue1");
}
public static function EnumValue2() {
return static::_get("EnumValue2");
}
}
use rikudou\PHPEnum\EnumTrait;
/**
* @method static static EnumValue1()
* @method static static EnumValue2()
*/
class MyCoolEnum
{
use EnumTrait;
}
use rikudou\PHPEnum\EnumTrait;
class MyCoolEnum
{
use EnumTrait;
private static function allowedValues()
{
return [
"Value1",
"Value2",
];
}
public static function Value3()
{
return static::_get("Value3");
}
}
function doSomething(MyCoolEnum $myCoolEnum)
{
switch ($myCoolEnum) {
case MyCoolEnum::Value1():
return "Value1";
case MyCoolEnum::Value2():
return "Value2";
// etc
}
}
use rikudou\PHPEnum\EnumTrait;
class MyCoolEnum {
use EnumTrait;
public static function MyCoolValue() {
return static::_get(1);
}
}
echo MyCoolEnum::MyCoolValue()->getValue(); // echoes 1
use rikudou\PHPEnum\EnumTrait;
class MyCoolEnum {
use EnumTrait;
public static function Value1() {
return static::_get("Value");
}
public static function Value2() {
return static::_get("Value"); // same as in Value1()
}
}
var_dump(MyCoolEnum::Value1() === MyCoolEnum::Value2()); // dumps true
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.