From 7f5fe891abd50bfb71cd48ee55eace37287f4b1d Mon Sep 17 00:00:00 2001 From: Milad Rahimi Date: Sat, 17 Jul 2021 21:30:06 +0430 Subject: [PATCH] support inhertance --- src/Enum.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Enum.php b/src/Enum.php index ed19e12..c2572ec 100644 --- a/src/Enum.php +++ b/src/Enum.php @@ -3,7 +3,7 @@ namespace MiladRahimi\Enum; use ReflectionClass; -use ReflectionException; +use Throwable; abstract class Enum { @@ -22,8 +22,12 @@ abstract class Enum public static function all(): array { try { - return static::$items ?: static::$items = (new ReflectionClass(static::class))->getConstants(); - } catch (ReflectionException $e) { + if (isset(static::$items[static::class])) { + return static::$items[static::class]; + } + + return static::$items[static::class] = (new ReflectionClass(static::class))->getConstants(); + } catch (Throwable $e) { return []; } } @@ -130,4 +134,4 @@ public static function randomValue() { return static::all()[array_rand(static::all())]; } -} \ No newline at end of file +}