Skip to content

potfur/enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enum for PHP

Usage

Definition

class EnumSample extends \Enum\Enum
{
    const FOO = 'foo';
    const BAR = 'bar';
    const YADA = 'yada';
}

There are four ways to create enum instance, each will create same value object. By constants name, by method with same name or with constants value

$enum = new EnumSample('FOO');
$enum = EnumSample::FOO();

$enum = new EnumSample('foo');
$enum = EnumSample::foo();

Why do it at all

It's easier to limit values accepted by argument to those in enumerable (enum). Just hint type in argument and thats it.

function imUsingEnum(EnumSample $sample) {
	echo $sample->value();
}

Releases

No releases published

Packages

No packages published

Languages