Skip to content

Instantly share code, notes, and snippets.

@the-toster
Created February 9, 2022 08:11
Show Gist options
  • Save the-toster/180eace28fb1407ff2001587f93e27a6 to your computer and use it in GitHub Desktop.
Save the-toster/180eace28fb1407ff2001587f93e27a6 to your computer and use it in GitHub Desktop.
Instantiate eunm by name
<?php
function enumByName(string $enumClass, string $case): object {
return (new \ReflectionEnum($enumClass))->getCase($case)->getValue();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment