PHP code example of zlikavac32 / php-enum

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

    

zlikavac32 / php-enum example snippets


/**
 * @method static YesNo YES
 * @method static YesNo NO
 */
abstract class YesNo extends \Zlikavac32\ZEnum\ZEnum
{

}

/**
 * @method static YesNo YES
 * @method static YesNo NO
 */
abstract class YesNo extends \Zlikavac32\ZEnum\ZEnum
{
    protected static function enumerate(): array
    {
        return [
            'YES' => new class extends YesNo {},
            'NO' => new class extends YesNo {}
        ];
    }
}

switch ($enum) {
    case YesNo::YES():
        // do something
    case YesNo::NO():
        // do something else
    default:
        throw new UnhandledEnumException($enum);
}

composer