Created
February 12, 2020 15:10
-
-
Save kobus1998/6765f229e0d440444a6f086c0919c7ac to your computer and use it in GitHub Desktop.
reflectionclass cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ReflectionCache | |
{ | |
protected $instance; | |
protected static $instances = []; | |
public function __construct($className) | |
{ | |
if (!isset(self::$instances[$className])) { | |
self::$instances[$className] = new ReflectionClass($className); | |
} | |
$this->instance = self::$instances[$className]; | |
} | |
public function get() | |
{ | |
return $this->instance; | |
} | |
} | |
class AAA | |
{ | |
public function doA($no) | |
{ | |
echo "AAA\n"; | |
} | |
} | |
$r1 = (new ReflectionCache("AAA"))->get(); | |
$r2 = (new ReflectionCache("AAA"))->get(); | |
echo $r1 === $r2 ? 'exactly the same' : 'not the same'; // exactly the same |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment