We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 4a27d4e + 067f53e commit b52c2f2Copy full SHA for b52c2f2
src/MyCLabs/Enum/Enum.php
@@ -20,6 +20,12 @@ abstract class Enum
20
* @var mixed
21
*/
22
protected $value;
23
+
24
+ /**
25
+ * Store existing constants in a static cache per object.
26
+ * @var array
27
+ */
28
+ private static $constantsCache = array();
29
30
/**
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
}
73
74
0 commit comments