-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Description
Implementing a trait than can simply be used to make an enumeration serializable.
As long as it's impossible in PHP to make a singleton serializable this functionality should be used carefully and needs to be implemented itself. This trait will help to activate it if really required.
Usage example:
use MabeEnum\Enum;
use MabeEnum\EnumSerializableTrait;
use Serializable;
class CardinalDirection extends Enum implements Serializable
{
use EnumSerializableTrait;
const NORTH = 'n';
const EAST = 'e';
const WEST = 'w';
const SOUTH = 's';
}
$north1 = CardinalDirection::NORTH();
$north2 = unserialize(serialize($north1));
var_dump($north1 === $north2); // FALSE <- this is the wrong behavior you could run into