1. Go to this page and download the library: Download victorwesterlund/xenum library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
victorwesterlund / xenum example snippets
use \victorwesterlund\xEnum;
enum HelloWorld: string {
use xEnum;
case FOO = "BAR";
case BAZ = "QUX";
}
// Like Enum::from() but for Enum names instead of values
HelloWorld::fromName("FOO"); // HelloWorld::FOO
// And of course the non-throwing version similar to Enum::tryFrom()
HelloWorld::tryFromName("MOM"); // null
use \victorwesterlund\xEnum;
enum HelloWorld {
use xEnum;
}
Enum::fromName(int|string|null): static
enum HelloWorld: string {
use xEnum;
case FOO = "BAR";
case BAZ = "QUX";
}
HelloWorld::fromName("FOO"); // HelloWorld::FOO
HelloWorld::fromName("MOM") // ValueError: 'MOM' is not a valid case for HelloWorld
Enum::tryFromName(int|string|null): static|null
enum HelloWorld: string {
use xEnum;
case FOO = "BAR";
case BAZ = "QUX";
}
HelloWorld::tryFromName("FOO"); // HelloWorld::FOO
HelloWorld::tryFromName("MOM") // null
Enum::names(): array
enum HelloWorld: string {
use xEnum;
case FOO = "BAR";
case BAZ = "QUX";
}
HelloWorld::names(); // ["FOO", "BAZ"]
Enum::entries(): array
enum HelloWorld: string {
use xEnum;
case FOO = "BAR";
case BAZ = "QUX";
}
HelloWorld::values(); // ["BAR", "QUX"]
Enum::entries(): array
enum HelloWorld: string {
use xEnum;
case FOO = "BAR";
case BAZ = "QUX";
}
HelloWorld::entries(); // ["FOO" => "BAR", "BAZ" => "QUX"]
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.