我試圖做的是以下幾點:PHP:調用一個實例的靜態類中實例的私有方法
class A {
public function __construct($a) {
// stuff here
}
public static function request() {
$instance = new self("hi");
$instance->bye(); // this weirdly only sometimes throws errors
}
private function bye() {
// stuff here
}
}
A::request();
的關注線是$instance->bye()
- 這是允許的靜態範圍內的方式,但是當調用一個實例,並在構造函數相同的類內?或者這通常不是一個好習慣?奇怪的是,這隻會在調用沒有上下文的私有方法時拋出錯誤。
任何幫助表示讚賞!
http://php.net/manual/en/language.oop5.visibility .php#如果拉nguage.oop5.visibility-other-objects – Federkun
我無法重現錯誤。你使用的是什麼版本的PHP? – wogsland
@wogsland發佈的評論 - 顯然這是由於PHPStorm調試 – Sasha