在include中运行脚本时发生PHP错误
我有一个PHP脚本,它给了我一个错误: 正在尝试获取/home/include/common.php第20行中非对象的属性 这是common.php文件在include中运行脚本时发生PHP错误,php,Php,我有一个PHP脚本,它给了我一个错误: 正在尝试获取/home/include/common.php第20行中非对象的属性 这是common.php文件 function Template($name, $type = -1) { // todo: default $name from the script name withouth the extension? $this->path = Template::getPath($name, $type);// th
function Template($name, $type = -1) {
// todo: default $name from the script name withouth the extension?
$this->path = Template::getPath($name, $type);// this is the line 20
// todo: verify the existance of the file
// and throw the fatal error if not available
}
我的PHP不是很好,我不确定我的PHP配置文件中是否缺少一些PHP模块或其他问题,如果有任何帮助,我们将不胜感激。谢谢。模板是一个类吗?如果是,那么
函数模板($name,$type=-1)
应该是构造函数吗
因为如果是这样的话,这不适合PHP
在PHP中使用(例如):
作为一个构造器
第二,如果您想在PHP中调用同一类中的静态方法,可以通过(例如):
我希望这能解决你的问题
因此,对静态调用使用self::
,对对象调用使用$this->
如果您也需要析构函数,这将是
\uuuu destruct
(前面有一个uuuu的方法称为“神奇方法”,您可能需要查看很多有用的东西;-))。几天前脚本运行良好,然后我的托管公司在php上更改了一些内容,现在它给出了错误,因此我不确定是否有php模块丢失。感谢您的帮助,我能够解决问题很高兴您修复了它:-)
function __construct($name, $type = -1);
self::getPath($name, $type);