这段代码是我写的
include('database.php');
function get_something() {
database instructions
}
function get_another(){
database instructions
}
我尝试通过这个来解决
function get_something() {
include('database.php');
database instructions
}
function get_another(){
include('database.php');
database instructions
}
我收到重新声明错误。
我该如何解决这个问题?
谢谢
最佳答案
要么在保证只执行一次的应用程序中包含所有文件,要么使用 include_once 'database.php';
仔细阅读 here 。 或者,您可以实现 autoloading 。当且仅当需要时,PHP 才会加载类。但它不适用于全局函数(因为它们不是类)。如果您想利用这一点,您必须将它们包装在一个类中。
关于php - include 和 require 函数中的声明错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1328715/