Last active
March 19, 2023 09:20
-
-
Save szepeviktor/3af0ad3aa45fae1103e4426fac9ef5fe to your computer and use it in GitHub Desktop.
Fun with PHP 8.1 backed enums
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This needs PHP 8.1 | |
enum Trinary: int | |
{ | |
case YES = 1; | |
case MAYBE = 0; | |
case NO = -1; | |
} | |
var_dump( | |
Trinary::NO->value, | |
Trinary::from(-1), | |
Trinary::MAYBE->name | |
); |
Author
szepeviktor
commented
Jan 8, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment