繁体   English   中英

包含中的PHP错误运行脚本

[英]PHP error running script in include

我有一个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);// this is the line 20

    // todo: verify the existance of the file
    // and throw the fatal error if not available
}

我的PHP不太好,我不确定我的php conf中是否缺少某些php模块或其他问题,我们将不胜感激,谢谢

模板是一堂课吗? 如果是, function Template($name, $type = -1)应该是构造函数吗?

因为如果是这样,这对于PHP来说是不合适的。

在PHP中,您可以使用(例如):

function __construct($name, $type = -1);

作为构造函数。

其次,如果要在PHP的同一类中调用静态方法,则可以通过以下方式进行操作:

self::getPath($name, $type);

我希望这能解决您的问题。

因此,您可以使用self::进行静态调用,并使用$this->进行对象调用。

如果您还需要Destruktor,则可以使用__destruct (前面带有__的方法称为“魔术方法”,您可能想看看很多有用的东西;-))。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM