PHP code example of philiagus / enum

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

    

philiagus / enum example snippets




/**
 * @method static SomeEnum VALUE_ONE
 * @method static SomeEnum VALUE_TWO
 */
class SomeEnum extends \Philiagus\Enum\CommentEnum
{
}

$anEnumValue = SomeEnum::VALUE_ONE();

function doSomething(SomeEnum $value): void
{
    switch ($value) { // objects work with switch construct
        case SomeEnum::VALUE_ONE():
            echo 'ONE';
            break;
        case SomeEnum::VALUE_TWO();
            echo 'TWO';
            break;
    }
}

doSomething($anEnumValue); // would print 'ONE'

var_dump(SomeEnum::all());
/*
Prints an array with the keys being the enum names (VALUE_OND and VALUE_TWO) and the values being the corresponding enum instances.
*/