PHP code example of aldemeery / enum-polyfill

1. Go to this page and download the library: Download aldemeery/enum-polyfill 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/ */

    

aldemeery / enum-polyfill example snippets



class Month extends \SplEnum {
    const __default = self::January;

    const January = 1;
    const February = 2;
    const March = 3;
    const April = 4;
    const May = 5;
    const June = 6;
    const July = 7;
    const August = 8;
    const September = 9;
    const October = 10;
    const November = 11;
    const December = 12;
}

echo new Month(Month::June) . PHP_EOL;

try {
    new Month(13);
} catch (\UnexpectedValueException $uve) {
    echo $uve->getMessage() . PHP_EOL;
}

abstract class SplEnum
{
    /* Constants */
    const NULL __default = NULL ;

    /* Methods */
    SplType::__construct ([ mixed $initial_value ] )

    public array getConstList ([ bool $

/* The default value of the enum */
SplEnum::__default

SplType::__construct ([ mixed $initial_value ] )

public array SplEnum::getConstList ([ bool $