Class EnumAbstract
A simple-to-use PHP class that provides the ability to emulate and create type-safe enumerations.
Definition:
class ColorEnum extends EnumAbstract { public static $RED; public static $GREEN; public static $BLUE; }
Usage:
// One call per enumeration is necessary and sufficient, // typically at the top of the program, during instantiation phase: ColorEnum::buildInstances(); $color = ColorEnum::$RED; var_dump((string)$color); // string(3) "RED" var_dump(ColorEnum::$RED === ColorEnum::RED()); // true function f (ColorEnum $color) { switch($color) { case ColorEnum::$RED: … } … } f(ColorEnum::$RED);
Copyright (c) 2013 Geoffroy Aubry <geoffroy.aubry@free.fr> Licensed under the GNU Lesser General Public License v3 (LGPL version 3).
Abstract
Namespace: GAubry\Enum
Copyright: 2013 Geoffroy Aubry <geoffroy.aubry@free.fr>
License: http://www.gnu.org/licenses/lgpl.html
Located at GAubry/Enum/EnumAbstract.php
Namespace: GAubry\Enum
Copyright: 2013 Geoffroy Aubry <geoffroy.aubry@free.fr>
License: http://www.gnu.org/licenses/lgpl.html
Located at GAubry/Enum/EnumAbstract.php
protected
|
|
public static
string
|
|
public static
array
|
|
public static
array
|
|
public static
|
#
__callStatic( string $sName, array $aArgs )
Get enum instances with lazy instanciation. Triggered when invoking inaccessible methods in a static context. |
public
string
|
|
final public
|
private static
integer
|
$iCounter | 0 |
#
Global static counter to ensure that each EnumAbstract instance is unique. |
private static
array
|
$aCache | array() |
#
A cache of all enum values to increase performance. Structure: array( 'class' => array( 'key' => EnumAbstract instance, … ), … ) |
private
integer
|
$iValue | |
#
A unique value to ensure that each EnumAbstract instance is unique. |
private
string
|
$sName | |
#
Name of enum instance, used by __toString(). |