doy2255 2017-12-18 21:06
浏览 84

在遗留应用程序中管理PHP全局变量

We have a legacy application which doesn't use any of our nice modern frameworks. One problem we're trying to deal with is pollution of the global namespace. As a contrived example, the entry point for the app is file1.php; it requires files, those files require other files...and many of them create variables:

file1.php

$color = 'purple';
require('file2.php');
require('file3.php');

file2.php

$sound = 'waterfall';
require('file4.php');

Eventually, after a few dozen of these files which make up this custom "framework", we get to our actual page.php where we can write our page-specific code for page.html. Problem is, $color and $sound were created way back in file1 and file2, so now we have to be extremely careful not to accidentally use these variables in our page-specific code.

Any ideas? Would maybe unseting all of these variables immediately before page.php (in the primary "router" I guess) work?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划