【发布时间】:2016-02-16 22:54:32
【问题描述】:
所以,我有一个名为 init.php 的文件,它应该放在我网站上每个页面的顶部。在这种情况下,它在我的 index.php 中。在该 init.php 中是一段代码,其中包含一个名为 include 的文件夹中的所有文件。当我尝试在应该包含的文件中定义的 index.php 文件中调用一个函数时,我只收到一条错误消息Call to undefined function errors_return()。知道这里有什么问题吗?
//index.php
<?php
include "php\init.php";
//errors_return(); is a defined function in functions.php
?>
//init.php
<?php
//error_reporting(0);
foreach (glob("include\*.php") as $filename) {
include $filename;
}
$GLOBALS["errors_log"] = array();
session_start();
?>
//sample of functions.php
<?php
function error($msg = "default error"){
array_push($GLOBALS["errors_log"],$msg);
}
function errors_return(){
if(!empty($GLOBALS["errors_log"])){
foreach($GLOBALS["errors_log"] as $e){
echo '<p style="position:relative;">'.$e.'</p>';
}
}
else {
return null;
}
}
?>
folder structure
root (folder)
index.php
php (folder)
init.php
include (folder)
functions.php
【问题讨论】:
-
使用
/作为目录分隔符 -
也试过了,但什么也没做。
-
glob会返回您期望的结果吗? -
试试require看看有没有错误
-
仍然给出相同的
Call to undefined function errors_return()
标签: php php-include