1. Go to this page and download the library: Download vjik/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/ */
vjik / php-enum example snippets
use Vjik\Enum\Enum;
/**
* @method static self NEW()
* @method static self PROCESS()
* @method static self DONE()
*/
final class Status extends Enum
{
private const NEW = 'new';
private const PROCESS = 'process';
private const DONE = 'done';
}
$process = Status::from('process');
$process = Status::tryFrom('process'); // Status object with value "process"
$process = Status::tryFrom('not-exists'); // null