3v4l.org

run code in 500+ PHP versions simultaneously
<?php enum MethodConstraint :string { case A = "a"; case B = "b"; case C = "c"; public function getMethod(): string { return $this->value; } public function getMethodSentence($value): string { return match ($value) { MethodConstraint::A => "This is an A char", MethodConstraint::B => "This is a B char", MethodConstraint::C => "This is a C char" }; } public function getCharAndSentence(): string { return $this->getMethod()." ".$this->getMethodSentence($this); } } $aChar = MethodConstraint::A; echo $aChar->getMethod().PHP_EOL; echo $aChar->getMethodSentence(MethodConstraint::B).PHP_EOL; echo $aChar->getCharAndSentence();
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.7
a This is a B char a This is an A char

preferences:
37.31 ms | 985 KiB | 4 Q