我的PHP include函数一直有问题。所以有人能向我解释为什么这会起作用吗。。。
//testfile1.php
<?php
include 'file1.php';
?>
//testfile2.php
<?php
include 'file2.php';
?>
但这行不通。。
//testfile.php
<?php
include 'file1.php';
include 'file2.php';
?>
有没有将第二个文件包含在主文件中?我假设将两个php文件简化为一个主文件并运行它。(所有文件都在同一个目录上,可以"看到"彼此,没有问题。)
尝试将include语句更改为includeonce。在包含的文件中查找包含并更改它们。
如果file1.php还包括file2.php本身,并且文件2有一个函数声明,那么您可能会重新声明一个同名的函数。
看起来您将include与可能被包含两次或根本没有被包含的文件重叠。在这种情况下,您需要使用任一
include_once()
而不是include()
你也可以使用
如果需要包含,则使用require_once()
而不是include()
//使用此选项