php - 使用函数中包含的函数和变量
问题描述
我想在函数的包含文件中使用在另一个 php 文件中定义的变量。
我有这样的事情:
/* INDEX.PHP */
require('main.php');
require('utils.php');
$error = ([condition]);
if ($error) {
error_404();
}
require('page.php'); //The normal content of the page, replaced by error404.php in case of error
/* UTILS.PHP */
function error_404() {
header('HTTP/1.0 404 Not Found');
include('error404.php'); //This file needs the 'main.php' required outside the function.
exit();
}
函数包含的error404.php
文件error_404()
需要使用函数main.php
外包含的文件中声明的函数和变量。
我需要“将包含移动main.php
到功能环境”之类的东西。有谁知道我该如何解决这个问题?
解决方案
推荐阅读
- python - 熊猫大文本过滤一列
- sql-server - 有没有办法同时使用 SQL Server 2019 和 CDC(变更数据捕获)?
- rust - 在 Rust 中,是否有用于连续“折叠”流的功能,即与状态进行映射?
- unreal-engine4 - 编译 Unreal Lightmass。在 Linux 上从源代码构建 Unreal 4.24 时出错
- php - 重新加载页面PHP时如何检查MySQL表是否为空
- kubernetes - Kubernetes Statefulset 访问和停机时间
- windows - 如何使批处理脚本从任何地方执行?
- python - 指数平滑 - 如何选择 alpha、beta、gamma
- laravel - 如何在 laravel 私聊中保存聊天记录
- ecto - 当我有一个主键并且它有一个值时,为什么 ecto 会引发 Ecto.NoPrimaryKeyValueError?