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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog