Undefined Index Error Reporting in WAMP and PHP
Solution 1
If you don't want to change error_reporting level you should check, is variable exists, before using it. 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');
Solution 2
You can just turn off the mechanism in php.ini.
This thread would help you.
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
error_reporting = E_ALL to error_reporting = E_ALL & ~E_NOTICE
ShoeLace1291
Updated on August 22, 2022Comments
-
ShoeLace1291 almost 2 years
I'm using wamp to develop a php application. 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. There are areas of my application that make this method inefficient.
-
ShoeLace1291 almost 13 yearsI may have explained the situation badly. What I want to do is instead of an undefined variable returning an error when it's called, I want to have it be returned as a blank string($x = '') or something like that. Not change the style of the error reports.