PHP反射和注入
我有一个类,该类缓存已通过反射实例化的其他类。是否可以从缓存类中执行函数,而不注入已缓存的所有其他内容?以下是一个例子:PHP反射和注入,php,reflection,Php,Reflection,我有一个类,该类缓存已通过反射实例化的其他类。是否可以从缓存类中执行函数,而不注入已缓存的所有其他内容?以下是一个例子: <?php class cache { private $cache = []; public function __construct() { $test1 = new ReflectionClass('test1'); $this->cache['test1'] = $test1->newIns
<?php
class cache
{
private $cache = [];
public function __construct()
{
$test1 = new ReflectionClass('test1');
$this->cache['test1'] = $test1->newInstanceWithoutConstructor();
$test2 = new ReflectionClass('test2');
$this->cache['test2'] = $test2->newInstanceWithoutConstructor();
$this->cache['test2']->init($this);
}
public function say_hello($text)
{
echo $text;
}
}
class test1
{
public $data = 'foobar';
}
class test2
{
public function init($con)
{
$con->say_hello('hello there');
}
}
new cache;