簡體   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