简体   繁体   English

包含中的PHP错误运行脚本

[英]PHP error running script in include

I have a script in PHP that gives me an error: 我有一个PHP脚本,给了我一个错误:

Trying to get property of non-object in /home/include/common.php line 20 尝试在/home/include/common.php第20行中获取非对象的属性

this is file common.php 这是文件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
}

I am not so good in PHP and I am not sure if there is some php module missing in my php conf or another problem, any help would be appreciated thanks 我的PHP不太好,我不确定我的php conf中是否缺少某些php模块或其他问题,我们将不胜感激,谢谢

Is Template a class? 模板是一堂课吗? If yes, should function Template($name, $type = -1) be the constructor? 如果是, function Template($name, $type = -1)应该是构造函数吗?

Because if so, this isn't right for PHP. 因为如果是这样,这对于PHP来说是不合适的。

In PHP you use (eg): 在PHP中,您可以使用(例如):

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

as a constructor. 作为构造函数。

Second, if you want to call a static method in the same class in PHP you do this by (eg): 其次,如果要在PHP的同一类中调用静态方法,则可以通过以下方式进行操作:

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

I hope this solves your problem. 我希望这能解决您的问题。

So you use self:: for static calls and $this-> for calls to the object. 因此,您可以使用self::进行静态调用,并使用$this->进行对象调用。

If you need a Destruktor as well this would be __destruct (Methods with a __ in front are called "magic methods" and there are a lot of useful things you may want to look at ;-) ). 如果您还需要Destruktor,则可以使用__destruct (前面带有__的方法称为“魔术方法”,您可能想看看很多有用的东西;-))。

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

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