加載php文件後,我的HTML-soure爲空。使用file_get_contents聲明私有變量時出錯
有人可以告訴我爲什麼我得到這個錯誤在聲明一個私有變量file_get_contents?
class Main {
private $order = file_get_contents("file.ini");
...
...
...
}
我使用PHP 28年3月5日,是的了allow_url_fopen =在
謝謝!
加載php文件後,我的HTML-soure爲空。使用file_get_contents聲明私有變量時出錯
有人可以告訴我爲什麼我得到這個錯誤在聲明一個私有變量file_get_contents?
class Main {
private $order = file_get_contents("file.ini");
...
...
...
}
我使用PHP 28年3月5日,是的了allow_url_fopen =在
謝謝!
這是不可能的。在構造方法中聲明它。
class Main {
private $order;
public function __construct(){
$this->order = file_get_contents("file.ini");
}
}
我希望這將有助於您:
class Main {
private $order;
public function __construct($path) {
$this->order = file_get_contents($path);
}
public function getOrder() {
return $this->order;
}
public function setOrder($path) {
$this->order = file_get_contents($path);
}
}
祝你好運!
謝謝,我讀了一些關於構造函數,但現在我明白了:) – 2014-10-10 14:36:58
我稍後會刪除此評論,無法發佈圖片...該死的 – 2014-10-14 12:32:43
請你舉個例子吧!我從來沒有使用過構造函數。 – 2014-10-10 14:19:23
@MartinDittrich只是做了 – 2014-10-10 14:21:44
非常感謝馬文! – 2014-10-10 14:34:07