We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
toArray
1 parent 4a27d4e commit 4ed0a01Copy full SHA for 4ed0a01
src/MyCLabs/Enum/Enum.php
@@ -20,6 +20,12 @@ abstract class Enum
20
* @var mixed
21
*/
22
protected $value;
23
+
24
+ /**
25
+ * Store instantiated reflection objects in a static cache.
26
+ * @var array
27
+ */
28
+ protected static $reflectionCache = array();
29
30
/**
31
* Creates a new value of some type
@@ -57,7 +63,10 @@ public function __toString()
57
63
58
64
public static function toArray()
59
65
{
60
- $reflection = new \ReflectionClass(get_called_class());
66
+ $calledClass = get_called_class();
67
+ if(!array_key_exists($calledClass, self::$reflectionCache)) {
68
+ self::$reflectionCache[$calledClass] = new \ReflectionClass($calledClass);
69
+ }
61
70
return $reflection->getConstants();
62
71
}
72
0 commit comments