请考虑以下代码:
final class TinkerWithMe {
protected $key1 = 19;
private $key2 = 88;
}
$class = new TinkerWithMe();
$getKeys = function() {
return array($this->key1, $this->key2);
};
$oldKeys = $getKeys->call($class);
$newKey1 = 96;
$newKey2 = 42;
$setKeys = function() use ($newKey1, $newKey2) {
$this->key1 = $newKey1;
$this->key2 = $newKey2;
};
$setKeys->call($class);
Run Code Online (Sandbox Code Playgroud)
当您可以通过闭包或反射轻松解决问题时,为什么还要考虑OOP的可见性?
有没有办法阻止我失踪的这种事情?