加载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