0

我已经阅读了几个已经存在与这个或类似名称的线程。似乎没有人能准确地解决我的情况。

我在utils.php课堂上遇到了这个错误。

Notice: Undefined variable: debug in /app/www/utils.php on line 89 Fatal error: Call to a member function debug() on a non-object in /app/www/utils.php on line 89

我这样定义变量debug

require_once('PHPDebug.php');
$debug = new PHPDebug();

然后像这样调用它(在第 89 行):

$debug->debug($message);

我如此困惑的原因是我从我的这些行中复制并粘贴了这些行,index.php并且该调用工作得很好。

如果需要,我可以包含指向index.phputils.php文件的链接,以及PHPDebug.php.

4

1 回答 1

3

感谢您的最后评论,您的问题的解决方案是$debugglobal函数内声明。因此,你应该有这样的东西:

require_once('PHPDebug.php');
$debug = new PHPDebug();

function myfunction()
{
   global $debug;

   // some code

   $debug->debug($message);
}

您可以在官方文档中阅读有关 global 的更多信息。

于 2011-11-20T03:11:10.700 回答