dongzi5673 2015-01-09 13:17
浏览 16
已采纳

PHP通知和警告

I have looked far and wide but haven't been able to find anything related to this specific situation, I am a backend developer and always write (something similar to):

if (!defined("something")) define("something", true);

instead of just

define("something"; true);

The second snippet will trigger a Notice if the file is included more than once. Similar situation with array indexes:

$data = array();
echo $data["does not exist"];

will trigger a notice, so my preferred way is to:

$data = array();
if (isset($data["does not exist"]) echo $data["does not exist"];
else echo "Missing info";

PHP has the ability to suppress these messages but I keep them enabled because I consider these checks good practice, but I lack the evidence to prove that they are needed and recently a coworker argued that there is no effect in coding without the checks.

Are you aware of any security implication in not writing the checks? or am I perhaps being paranoid and disabling the notices is acceptable?

PS: Not sure if this question is more suitable for StackOverflow but feel free to let me know and I'll try to move it.

  • 写回答

3条回答 默认 最新

  • dongyou4411 2015-01-09 20:58
    关注

    Avoiding notices is a good practice.

    Probably you should learn a little bit of defensive programming and follow The Right Way.

    Hiding errors and notices during the development can cause serious problems in future. Usually, notices tells you about bad programming style or non-obvious bugs, which tends to tricky bugs, unmaintainable code and security vulnerabilities.

    Good code never produce notices and errors because it controls the situation when they can happens.

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

报告相同问题?

悬赏问题

  • ¥15 关于自相关函数法和周期图法实现对随机信号的功率谱估计的matlab程序运行的问题,请各位专家解答!
  • ¥15 Python程序,深度学习,有偿私
  • ¥15 扫描枪扫条形码出现问题
  • ¥35 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥20 关于URL获取的参数,无法执行二选一查询