1 | <?php |
||
13 | class Cache |
||
14 | { |
||
15 | /** Cache singleton instance */ |
||
16 | private static $instance = array(); |
||
17 | |||
18 | /** |
||
19 | * Get the cache instance |
||
20 | * |
||
21 | * @param string $cacheConfig |
||
22 | * @return object |
||
23 | */ |
||
24 | public static function getCacheObject($cacheConfig = 'default') |
||
41 | |||
42 | /** |
||
43 | * Get the value stored at the given key |
||
44 | * |
||
45 | * @param string $key |
||
46 | * @param string $cacheConfig |
||
47 | */ |
||
48 | public static function get($key, $cacheConfig = 'default') |
||
52 | |||
53 | /** |
||
54 | * Put the supplied value into the given key |
||
55 | * |
||
56 | * @param string $key |
||
57 | * @param mixed $value |
||
58 | * @param string $cacheConfig |
||
59 | */ |
||
60 | public static function put($key, $value, $cacheConfig = 'default') |
||
64 | |||
65 | /** |
||
66 | * Check if the key exist |
||
67 | * |
||
68 | * @param string $key |
||
69 | * @param string $cacheConfig |
||
70 | * @return bool |
||
71 | */ |
||
72 | public static function has($key, $cacheConfig = 'default') |
||
76 | |||
77 | /** |
||
78 | * Retrieve the cache value and then delete it before returning that value |
||
79 | * |
||
80 | * @param string $key |
||
81 | * @param string $cacheConfig |
||
82 | * @return mixed |
||
83 | */ |
||
84 | public static function pull($key, $cacheConfig = 'default') |
||
91 | |||
92 | /** |
||
93 | * Remove an item from the cache |
||
94 | * |
||
95 | * @param string $key |
||
96 | * @param string $cacheConfig |
||
97 | * @return bool |
||
98 | */ |
||
99 | public static function delete($key, $cacheConfig = 'default') |
||
103 | |||
104 | /** |
||
105 | * Delete all cache keys (Purge) |
||
106 | * |
||
107 | * @param string $cacheConfig |
||
108 | * @return bool |
||
109 | */ |
||
110 | public static function clear($cacheConfig = 'default') |
||
114 | } |
||
115 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: