在PHP中从静态方法访问private


Accessing private from static method in PHP

为什么会这样?我的意思是,访问私有变量

<>之前类测试{Private $q = 0;公共函数__construct() {$this->q = 1;}EpicConstruct() {$test = new self();$test->q = 2;返回$测试;}}$test = test::EpicConstruct();

因为您正在正确的上下文中访问成员,即:定义私有成员的类。