File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,12 @@ abstract class Enum
20
20
* @var mixed
21
21
*/
22
22
protected $ value ;
23
+
24
+ /**
25
+ * Store existing constants in a static cache per object.
26
+ * @var array
27
+ */
28
+ private static $ constantsCache = array ();
23
29
24
30
/**
25
31
* Creates a new value of some type
@@ -57,8 +63,12 @@ public function __toString()
57
63
*/
58
64
public static function toArray ()
59
65
{
60
- $ reflection = new \ReflectionClass (get_called_class ());
61
- return $ reflection ->getConstants ();
66
+ $ calledClass = get_called_class ();
67
+ if (!array_key_exists ($ calledClass , self ::$ constantsCache )) {
68
+ $ reflection = new \ReflectionClass ($ calledClass );
69
+ self ::$ constantsCache [$ calledClass ] = $ reflection ->getConstants ();
70
+ }
71
+ return self ::$ constantsCache [$ calledClass ];
62
72
}
63
73
64
74
/**
You can’t perform that action at this time.
0 commit comments