douyalin2258 2013-08-22 15:20
浏览 33
已采纳

是否可以覆盖另一个文件中的变量

Forgive me if this is one of those dumb questions.

I'm writing a theme for wordpress and making use of PHP variables to communicate between files.

<?php
    $somevar = 'cat';
    $display = 10;
    include 'cat_display.php';
?>

It has suddenly ocured to me that while I am including my own files, Wordpress must be including my files. What if those variables that I think I have declared have already been declared up the chain and hold something important.

The last thing I want to do is open my .htaccess for abuse or have something unmeaningful added to the database.

$user_id = 10; // Oops just granted uberuser status to WillyWonka

Do I have anything to worry about?

  • 写回答

3条回答 默认 最新

  • douni9620 2013-08-22 15:25
    关注

    Yes, it certainly is.

    You could rename your variables $yourinitials_somevar to avoid the problem.

    [edit]Or put them in an array, as Christopher says in the question comments.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!