【问题标题】:Fatal error: Call to undefined function in file.php error / defined function致命错误:在 file.php 错误/已定义函数中调用未定义函数
【发布时间】:2013-09-11 11:05:40
【问题描述】:

我有一个 2007 年开发的网站。我一直在使用这个网站没有问题,但最近我遇到了如下 php 错误:

Fatal error: Call to undefined function getTitle() in comments.php error on line 3

$ptitle = htmlspecialchars(getTitle($row_cs['id'])); // line 3

这个函数在funcs.php文件中定义。

以下是我如何使用包含文件的文件;

index.php

include 'funcs.php'
...
...
...
include 'comments.php'

funcs.php

function getTitle($tid)
{
    $sql = mysql_query("select title from table where id = '".$tid."'");
    $title = mysql_fetch_row($sql);

    return $title[0];
}

我在 cmets.php 中调用 getTitle() 方法。
我没有直接在 cmets.php 中包含 funcs.php
两个文件(funcs.php 和 cmets.php)都包含在 index.php 中。我通常在 cmets.php 文件中使用 funcs.php 方法。

为什么我最近收到此错误,这是服务器配置问题吗?

感谢您的帮助。

【问题讨论】:

  • 显示调用 getTitle() 的代码
  • 您需要同时显示函数的定义位置和函数调用位置的代码
  • 下定决心,伙计。您的错误是“调用未定义函数”还是“调用非对象上的成员函数”?
  • 抱歉,我刚刚尝试转换为一个对象,然后从这个对象调用。但这没有任何区别,只是错误消息发生了变化。我已经编辑了问题。
  • 能否请您发布函数声明代码和调用函数的行?

标签: php undefined-function


【解决方案1】:

请使用单引号来包含文件。

include 'func.php';
include 'comments.php';

【讨论】:

  • 在 php 文件中,包含引号。此代码有效,最近我收到此错误。代码没有任何变化。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-05
  • 1970-01-01
  • 2012-07-18
  • 2017-01-25
  • 2012-06-28
相关资源
最近更新 更多