停止通知在PHP中显示

Ben*_*ock 8 php

我希望我的通知停止在PHP中显示.在代码中没有错误,它只是说未定义的索引.什么都无法做到.

那么如何阻止它显示呢?

Notice: Undefined variable: username in C:\wamp\www\watchedit\includes\config.php on line 37

Notice: Undefined variable: key in C:\wamp\www\watchedit\includes\config.php on line 42
Run Code Online (Sandbox Code Playgroud)

小智 25

这将以编程方式关闭环境通知 - 来自PHP.net.

// Report all errors except E_NOTICE   
error_reporting(E_ALL ^ E_NOTICE);  
Run Code Online (Sandbox Code Playgroud)

在某些地方,您可以在声明前加上"@",如果它引起通知,它将使该位置静音.

  • 不过,通知并不是代码的问题,只是建议。我不会忽视错误。 (2认同)
  • 更好:error_reporting(E_ALL&~E_NOTICE); (2认同)

Gum*_*mbo 8

isset在尝试读取其值之前,应检查变量是否存在.