PHP code example of desmart / php-enum

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

    

desmart / php-enum example snippets


/**
 * @method static Character good()
 * @method static Character evil()
 * @method static Character sometimesGoodSometimesEvil()
 */
class Character extends Enumeration
{
    const GOOD = 'good';
    const EVIL = 'evil';
    const SOMETIMES_GOOD_SOMETIMES_EVIL = 'sometimes_good_or_evil';
}

$enum = Character::good(); // or Character::fromName('good')

$enum = Character::fromValue('sometimes_good_or_evil');

Character::good()->equals(Character::fromName('good')); // true
Character::good()->equals(Character::evil());           // false
Character::good()->equals(OtherEnum::someValue());      // false

composer