【发布时间】:2018-03-29 11:39:59
【问题描述】:
main.php 需要 2 个文件:
require './functions/fileA.php';
require './functions/fileB.php';
fileA.pgp 作为函数
function doecho($url){echo $url}
在fileB.php中,我有一个调用doecho函数的函数
function withinBfunction($url){doecho($url);}
但我得到了这个错误,
Uncaught Error: Call to undefined function curl().
但是,如果在 fileB.php 中我在任何函数之外调用 doecho 函数,它就可以工作。 似乎fileB.php中的函数无法访问fileA.php中的函数
我看了这篇文章 (PHP Fatal error: Call to undefined function when function is defined) 但不同的是我没有使用类。有什么想法可以解决这个问题吗?
哦,是的,我已经使用 (error_reporting(E_ALL & ~E_NOTICE & E_STRICT & ~E_DEPRECATED) 打开了 php 错误日志,我得到的只是“调用未定义函数”。
【问题讨论】:
-
如果文件无法加载,
include不会死。使用require确保文件正确加载。 -
您确定包含
fileA.php吗?也许解释器找不到它,并且它触发的警告被您的配置所抑制。请改用require。 -
如果 PHP 说它不存在,它不存在,不管你怎么想。
-
可能是您在
include './functions/fileB.php';中缺少一个句点。试试include '../functions/fileB.php'; -
显示错误会对您有所帮助,请在寻求帮助之前尝试调试。 stackoverflow.com/q/5438060/3664960