Skip to content

Instantly share code, notes, and snippets.

@szepeviktor
Last active March 19, 2023 09:20
Show Gist options
  • Save szepeviktor/3af0ad3aa45fae1103e4426fac9ef5fe to your computer and use it in GitHub Desktop.
Save szepeviktor/3af0ad3aa45fae1103e4426fac9ef5fe to your computer and use it in GitHub Desktop.
Fun with PHP 8.1 backed enums
<?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
);
@szepeviktor
Copy link
Author

int(-1)
enum(Trinary::NO)
string(5) "MAYBE"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment