Skip to content

Commit 5d0b38e

Browse files
committed
Minor changes to caching
- Cache constants rather than reflection objects - Make static cache private
1 parent 4ed0a01 commit 5d0b38e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/MyCLabs/Enum/Enum.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ abstract class Enum
2222
protected $value;
2323

2424
/**
25-
* Store instantiated reflection objects in a static cache.
25+
* Store existing constants in a static cache per object.
2626
* @var array
2727
*/
28-
protected static $reflectionCache = array();
28+
private static $constantsCache = array();
2929

3030
/**
3131
* Creates a new value of some type
@@ -64,10 +64,11 @@ public function __toString()
6464
public static function toArray()
6565
{
6666
$calledClass = get_called_class();
67-
if(!array_key_exists($calledClass, self::$reflectionCache)) {
68-
self::$reflectionCache[$calledClass] = new \ReflectionClass($calledClass);
67+
if(!array_key_exists($calledClass, self::$constantsCache)) {
68+
$reflectin = new \ReflectionClass($calledClass);
69+
self::$constantsCache[$calledClass] = $reflection->getConstants();
6970
}
70-
return $reflection->getConstants();
71+
return self::$constantsCache[$calledClass];
7172
}
7273

7374
/**

0 commit comments

Comments
 (0)