Linux 如何在 PHP 中忽略未定义的变量错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5061432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 02:56:41  来源:igfitidea点击:

How to ignore undefined variable error in PHP

phplinux

提问by webnat0

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?

我最近设置了一个新的 Web 服务器,但出现未定义变量错误。如果我在没有初始化的情况下使用变量,它会给我一个错误。源代码没有改变。只有 LAMP 环境可以。你会如何解决这个问题?

Thanks

谢谢

采纳答案by Orbling

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.

  1. 您应该定义所有变量,这些警告是有原因的,以使您编写更好的代码。未定义的变量很容易导致变量名称出现拼写错误。

  2. 您可以更改 *error_reporting* 级别,高于 E_NOTICE 以摆脱它,但这是非常不可取的。

回答by Spechal

You can set notices to not show.

您可以将通知设置为不显示。

error_reporting(E_ALL & ~E_NOTICE)

You should be developing with

你应该开发

error_reporting(E_ALL | E_STRICT)

回答by antoniputra

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

您可以像人们所说的那样更改您的 error_reporting,但如果您想保留默认的 error_reporting 配置。您可以使用@运算符。例如:@$post