小编Nat*_*son的帖子

当闭包和反射可用时,PHP中的OOP可见性有什么意义?

请考虑以下代码:

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的可见性?

有没有办法阻止我失踪的这种事情?

php oop reflection closures class

15
推荐指数
1
解决办法
304
查看次数

标签 统计

class ×1

closures ×1

oop ×1

php ×1

reflection ×1