Jump to content

undefined index is a problem?


xiao

Recommended Posts

I get some errors Undefined index: something in ...

I know why I get them, I know how te remove them, but that would be a lot of unnecessary coding.

 

If I set error reporting off, I won't get them anymore. Is it actualy a problem in any way if a variable doesn't exist yet when I check what's in it?

Link to comment
Share on other sites

I do not see why it is a problem.  It seems rather pointless to turn the errors off, however, because you will not be able to see any errors that you may need to see.  I know you know this, but you could just do a quick !isset($var) to check, and then carry out the code.  That is not very much work to stop error messages.

Link to comment
Share on other sites

Yea, I know, but the problem is that I'd have to do an if(!isset($_SESSION['variable'])) && ...rest of checks... about 40 to 50 times more in my script just to get rid of some errors.

I'm only planning to turn off error reporting when everything else works fine.

Link to comment
Share on other sites

The output of the warning message is just the last step in the error response code that php executes every time it encounters a variable that does not exist. If you turn off display_errors or set the error_reporting level to prevent the errors from being displayed, all the rest of the error response code still gets executed as php tries to figure out for each undefined variable what to do on that line of code. The error response code takes about 20-30 times longer to execute than an isset() statement.

 

Code should not normally generate any warnings or notices. If you want your code to execute the quickest (important on a site getting 100's and 1000's of hits per second), take the time now to fix the problem that is causing the error response.

 

Turning off display_errors on a live server is only a safeguard to prevent unexpected and uncaught conditions in your logic from exposing path and variable information. It is not for the purpose of disabling the output of errors your code generates every time it executes.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.