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
https://forums.phpfreaks.com/topic/102382-undefined-index-is-a-problem/
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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.