开发者

How to ignore undefined variable error in PHP [duplicate]

This question already has answers here: &开发者_JS百科quot;Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP (29 answers) Closed 3 years ago.

I recently setup a new web server and I'm getting undefined variable error. If I use variables without initializing, it gives me an error. The source code did not change. Only the LAMP environment did. How would you solve this problem?

Thanks


Well...

  1. You should define all your variables, those warnings are there for a reason, to make you code better. Undefined variables can easily lead to typo errors in variable names.

  2. You can change the *error_reporting* level, above E_NOTICE to get rid of that, but it is highly unadvisable.


You can set notices to not show.

error_reporting(E_ALL & ~E_NOTICE)

You should be developing with

error_reporting(E_ALL | E_STRICT)


you can change your error_reporting as people said, but if you want keep the default error_reporting configuration. you may use @ operator. e.g: @$post

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜