PHP在include中运行脚本出错


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模块丢失在我的PHP conf或其他问题,任何帮助将不胜感激,谢谢

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

在PHP中使用(例如):

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

作为构造函数。

第二,如果你想在PHP的同一个类中调用一个静态方法,你可以这样做(例如):
self::getPath($name, $type);

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

使用self::进行静态调用,使用$this->进行对象调用。

如果你也需要一个析构函数,这将是__destruct(前面有__的方法被称为"魔法方法",有很多有用的东西你可能想看看;-))。