为什么这有效?我的意思是,访问私有(private)变量。
class Test { private $q = 0; public function __construct() { $this->q = 1; } public static function EpicConstruct() { $test = new self(); $test->q = 2; return $test; } } $test = Test::EpicConstruct();
最佳答案
因为您正在正确的上下文中访问该成员,即:定义私有(private)成员的类。
关于php - 从 PHP 中的静态方法访问私有(private),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15510421/