dongzhong8834 2013-07-25 10:54
浏览 43

在这种情况下取​​消设置PHP变量是不错的做法?

Right now, I am using a modified version of OsCommerce that has a lot of variables declared in its application_top.php file (which is included when going to every file on the website as the first thing).

So for instance, if I go to mypage.php, application_top.php is included in the top.

I only want some of the variables defined from my application_top.php file to be accessible inside the mypage.php file, since they are used for temporary calculations or whatever, whereas others are meant to be accessible from the page.

What would be the best practise? To unset variables that are meant to be used in the local scope after use, and to leave all variables that are meant to be accessed alone?

  • 写回答

1条回答 默认 最新

  • douwen1929 2013-07-25 11:03
    关注

    use of classes would be the best way, and just passing the variables you need

    Though I assume this will be a major rewrite ?

    What about something like this

    $vars = array_keys(get_defined_vars());
    $whitelist = array("var1", "var2" ...);
    $vars = array_diff(array_keys($whitelist), $vars);
    foreach($vars as $var) {
        unset($$var); 
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题