CKTIS / PHP
Keyword enum
Define a closed set of singleton cases.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
enum Phase: string { case Ready = "R"; }Define a closed set of singleton cases. A backed enum gives every case a distinct value of one common type, int or string. tryFrom() returns null for an unknown backing value, and from() throws ValueError. Instances are selected with :: and cannot be constructed using new.
enum Phase:string {case Ready="R"; case Done="D";}
echo json_encode([Phase::from("R")===Phase::Ready,Phase::Ready->value,Phase::tryFrom("X")]);
[true,"R",null]
Examples
<?php
enum Phase:string {case Ready="R"; case Done="D";}
echo json_encode([Phase::from("R")===Phase::Ready,Phase::Ready->value,Phase::tryFrom("X")]);
Result
[true,"R",null]