PHP code example of devionz / enum
1. Go to this page and download the library: Download devionz/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/ */
devionz / enum example snippets
use Devionz\Enum\Enum;
class Status extends Enum
{
private const DRAFT = 'draft';
private const PUBLISHED = 'published';
private const PENDING = 'pending';
}
function getValue(Status $status) {
return $status->value;
}
$enum1 = Status::DRAFT();
$enum2 = Status::from('draft');
$enum3 = Status::tryFrom('draft');
echo $enum1->name; // 'DRAFT'
echo $enum1->value // 'draft'
echo getValue($enum1); // 'draft
var_dump($enum1 === $enum2); // Returns true