Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Enumeration methodsEnumeration constants>
^EnumerationsLast updated: Mon, 26 Oct 2026

Enumeration static methods

Enumerations may also have static methods. The use for static methods on the enumeration itself is primarily for alternative constructors. E.g.:

<?php

enum Size
{
    case Small;
    case Medium;
    case Large;

    public static function fromLength(int $cm): self
    {
        return match (true) {
            $cm < 50 => self::Small,
            $cm < 100 => self::Medium,
            default => self::Large,
        };
    }
}

var_dump(Size::fromLength(50));

Static methods may be public, private, or protected, although in practice private and protected are equivalent as inheritance is not allowed.


<Enumeration methodsEnumeration constants>
^EnumerationsLast updated: Mon, 26 Oct 2026