PHP code example of enderive / enum

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

    

enderive / enum example snippets


use Enderive\Enum;

/**
 * Pure enum
 * 
 * @method static UserStatus ADMIN() 
 * @method static UserStatus MEMBER()
 * @method static UserStatus GUEST()
*/
class UserStatus extends Enum {}

/**
 * Backed enum
*/
class UserStatus extends Enum
{
    private const ADMIN = 1;
    private const MEMBER = 2;
    private const GUEST = 3;
}

UserStatus::ADMIN();
UserStatus::from(1);
UserStatus::tryFrom(1);
UserStatus::cases();

// Enums are singletons
UserStatus::ADMIN() === UserStatus::ADMIN() // => true

$status = UserStatus::from(1);
$status->name // "ADMIN"
$status->value // 1