我正在試圖在變量$ this的構造函數上訪問我的實例,在所有其他方法似乎工作很好,當我打電話$this->event->method()
但這種方法,把我的錯誤
在不對象上下文使用$此
我只是做了對這個問題的研究我發現的答案都是關於PHP的版本,但我有版本5.4。可能是什麼問題?
這是我嘗試調用該實例的方法。
// all protected variable $event , $team , $app
function __construct(EventTeamInterface $event,TeamInterface $team) {
$this->event = $event;
$this->team = $team;
$this->app = app();
}
/**
* @param $infos array() |
* @return array() | ['status'] | ['msg'] | ['id']
*/
public static function createEvent($infos = array()){
$create_event = $this->event->create($infos);
if ($create_event) {
$result['status'] = "success";
$result['id'] = $create_event->id;
} else {
$result['status'] = "error";
$result['msg'] = $create_event->errors();
}
return $result;
}
謝謝你的確切和明確的答案! – Fabrizio
從php 5.4.0開始,閉包(匿名函數)現在支持$ this:http://php.net/manual/en/migration54.new-features.php –