PHP code example of freshp / php-enumeration

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

    

freshp / php-enumeration example snippets


use FreshP\PhpEnumeration\Enum;

class EnumExample extends Enum
{
    public const TEST_CONSTANT = 'constant';
    public const TEST_DEFAULT = 'default';
    
    protected function getDefault(): string
    {
        return self::TEST_DEFAULT;
    }
}

use FreshP\PhpEnumeration\Enum;

/**
 * @method static self TEST_CONSTANT()
 * @method static self TEST_DEFAULT()
 */
class EnumExample extends Enum
...

class EnumExample extends Enum
{
...
    public static function listAllOptions(): array
    {
        return self::toArray();
    }
...

    $enum = EnumExample::TEST_CONSTANT();
    

    $enum = new EnumExample(EnumExample::TEST_CONSTANT);
    

    $enum = new EnumExample();
    

   $enum->__toString() === EnumExample::TEST_CONSTANT
    

   $enum->isEqual(EnumExample::TEST_CONSTANT())
    

composer