Skip to content

ycecube/php-type-enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Type - Enum

Defines a base class for emulating enum types in php.

Usage

<?php declare(strict_types=1);

use PhpType\Enum;

final class Day extends Enum {

    public static function Monday(): Day
    {
        return new static(0);
    }

    public static function Tuesday(): Day
    {
        return new static(1);
    }

    public static function Wednesday(): Day
    {
        return new static(2);
    }

    // ...
}

function isMonday(Day $day) {
  return $day->equals(Day::Monday());
}

isMonday(Day::Monday()); // Returns true.
isMonday(Day::Tuesday()); // Returns false.

About

Base class for emulating enum types in php.

Resources

License

Stars

Watchers

Forks

Packages

No packages published