1. Go to this page and download the library: Download php-compatible/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/ */
php-compatible / enum example snippets
use PhpCompatible\Enum\Enum;
use PhpCompatible\Enum\Value;
/**
* @method static Value hearts()
* @method static Value diamonds()
* @method static Value clubs()
* @method static Value spades()
*/
class Suit extends Enum
{
protected $hearts; // 0
protected $diamonds; // 1
protected $clubs; // 2
protected $spades; // 3
}
echo Suit::hearts()->name; // "hearts"
echo Suit::hearts()->value; // 0
class Status extends Enum
{
protected $pendingReview;
}
// All of these return the same Value instance:
Status::pendingReview(); // camelCase
Status::PendingReview(); // PascalCase
Status::PENDING_REVIEW(); // SCREAMING_SNAKE_CASE
Status::pending_review(); // snake_case
// The name property preserves the original definition:
Status::PENDING_REVIEW()->name; // "pendingReview"
/**
* @method static Value hearts()
* @method static Value diamonds()
* @method static Value clubs()
* @method static Value spades()
*/
class Suit extends Enum
{
protected $hearts;
protected $diamonds;
protected $clubs;
protected $spades;
}
use PhpCompatible\Enum\Enum;
use PhpCompatible\Enum\EnumLabel;
class Status extends Enum
{
protected $draft;
protected $published = 10;
}
$status = Status::draft();
echo EnumLabel::from($status);
use PhpCompatible\Enum\Php8EnumLabel;
enum Status: int
{
case draft = 0;
case published = 10;
}
$status = Status::draft;
echo Php8EnumLabel::fromEnum($status);
// PHP 8.1+
enum Status {
case PendingReview;
case InProgress;
}
echo Php8EnumLabel::fromEnum(Status::PendingReview); // "Pending Review"
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.