简体   繁体   English

WAMP和PHP中未定义的索引错误报告

[英]Undefined Index Error Reporting in WAMP and PHP

I'm using wamp to develop a php application. 我正在使用wamp来开发一个php应用程序。 My problem is that everytime I call a variable that sometimes happens to not have a value, I get an error that says it's an undefined index. 我的问题是,每当我调用一个有时碰巧没有值的变量时,我会得到一个错误,表明它是一个未定义的索引。 Is there a way to change the error reporting to not display this error? 有没有办法将错误报告更改为不显示此错误? I have to use isset to determine if it's set or not before I output the variable, but I don't want to have to do this. 在输出变量之前,我必须使用isset来确定它是否已设置,但我不想这样做。 There are areas of my application that make this method inefficient. 我的应用程序中有一些区域使这种方法效率低下。

If you don't want to change error_reporting level you should check, is variable exists, before using it. 如果您不想更改error_reporting级别,则应在使用之前检查,是否存在变量。 You may use 你可以用

 if(isset($var)) 

for it. 为了它。 You may add some function, to not write it always. 你可以添加一些功能,不要总是写它。 Example: 例:

 function getPost($name,$default=null){
     return isset($_POST[$name])?$_POST[$name]:$default;
 }

Usage: 用法:

getPost('id');
getPost('name','Not Logged In');

You can just turn off the mechanism in php.ini. 你可以在php.ini中关闭机制。

This thread would help you. 这个帖子可以帮到你。

http://www.wampserver.com/phorum/read.php?2,70609,70700 http://www.wampserver.com/phorum/read.php?2,70609,70700

But it generally its better to take care of undefined variables as they might save you some run time trouble. 但通常最好处理未定义的变量,因为它们可能会为您节省一些运行时间的麻烦。

Update: 更新:

In php.ini change 在php.ini中更改

error_reporting = E_ALL to error_reporting = E_ALL & ~E_NOTICE error_reporting = E_ALL到error_reporting = E_ALL&~E_NOTICE

Try this: 试试这个:

if(!isset($var)) $var=""; if(!isset($ var))$ var =“”;

PHP.ini files reside in both : PHP.ini文件驻留在两者中:

bin\\php\\php5.x 斌\\ PHP \\ php5.x

and

bin\\apache\\apache2.x\\bin BIN \\ apache的\\ apache2.x \\ BIN

be sure to make the changes in the apache folder version . 一定要在apache文件夹版本中进行更改


Also setting : 还设置:

display_errors = Off display_errors =关闭

display_startup_errors = Off display_startup_errors =关闭

error_reporting = E_ALL error_reporting = E_ALL

log_errors = On log_errors =开

leaves errors from being displayed on the client, but still allows them to be logged in the error log. 使错误不会显示在客户端上,但仍允许它们记录在错误日志中。

There are multiple ways to get around this: 有多种方法可以解决这个问题:
error_reporting(0) Use this at the top of your script error_reporting(0)在脚本的顶部使用它
set display_errors = Off in php.ini 在php.ini中设置display_errors = Off
Use '@' before the statement that generates an error 在生成错误的语句之前使用“@”

But unless you are writing something trivial you absolutely must use array_key_exists or if(!empty($arrayName['key'])) for everything sent by the user. 但除非你正在写一些微不足道的东西,否则你必须使用array_key_existsif(!empty($arrayName['key']))来为用户发送的所有东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM