从另一个php文件调用未定义的函数 [英] Call to undefined function from another php file
问题描述
好吧这就是我的代码看起来像
Alright this is what my code looks like
index.php
require_once($WebsiteRoot . "/include/testfile.php");
TestFunction();
/include/testfile.php
function TestFunction()
{
echo "It Works";
}
它给了我错误:
Fatal error:
Call to undefined function TestFunction() in /path/index.php on line 49
知道我做错了什么吗?
谢谢
Any idea what i'm doing wrong? Thanks
推荐答案
确保包含您认为自己的文件。如果您的 index.php
页面看起来与您所说的完全一致,那么它将不会返回任何内容。
Make sure you're including the file you think you are. If your index.php
page looks exactly like you've stated, then it won't return anything.
如果您想从网站上的任何位置链接到同一位置而不必担心相对位置,那么在文件的开头,输入:
If you want to link to the same location from anywhere on the site without worrying about relative locations, then at the beginning of the file, put:
$WebsiteRoot=$_SERVER['DOCUMENT_ROOT'];
它应该可以正常工作,只要你的文件位于 http://mywebsite.com/include/testfile.php
And it should work fine, provided your file would be located at http://mywebsite.com/include/testfile.php
这篇关于从另一个php文件调用未定义的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!