hws Posted November 19, 2009 Share Posted November 19, 2009 Should you never have: error_reporting(E_ALL & ~E_NOTICE); in development scripts? Just wondering as a my friend showed me an error inside that script that i'm unable to see from my side. It was already validated via javascript before this showed the error. It doesn't show the error for me. Quote Link to comment https://forums.phpfreaks.com/topic/182174-error_reportinge_all-~e_notice/ Share on other sites More sharing options...
Daniel0 Posted November 19, 2009 Share Posted November 19, 2009 error_reporting(E_ALL); would be a good idea. You would want to catch those E_NOTICEs as well. Quote Link to comment https://forums.phpfreaks.com/topic/182174-error_reportinge_all-~e_notice/#findComment-961189 Share on other sites More sharing options...
Maq Posted November 19, 2009 Share Posted November 19, 2009 Make sure you have this set as well: ini_set ("display_errors", "1"); Quote Link to comment https://forums.phpfreaks.com/topic/182174-error_reportinge_all-~e_notice/#findComment-961191 Share on other sites More sharing options...
hws Posted November 19, 2009 Author Share Posted November 19, 2009 this is what i have: <?php ini_set('display_errors', 'On'); //ob_start("ob_gzhandler"); error_reporting(E_ALL & ~E_NOTICE); //error_reporting(E_ALL); ini_set('display_errors', true); ?> But if i take that code off will the vailidation error in the php file not show the error and produce the form? and use error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/182174-error_reportinge_all-~e_notice/#findComment-961198 Share on other sites More sharing options...
DavidAM Posted November 19, 2009 Share Posted November 19, 2009 Depends on what kind of programmer you are. E_NOTICE are errors that the parser can recover from after making certain assumptions. If you write: $B = 100; $A = $b + 1; you will get an E_NOTICE that $b does not exist. PHP will treat it as 0 (zero) and continue. So, in this case, $A will be set to 1 and the code continues. However, if you meant to write: $B = 100; $A = $B + 1; (note the second $b is now capitalized). $A should be 101. But with E_NOTICE off, if you typed my first example, you don't know that there was a problem and your script is running with an incorrect value. You should always declare all variables before using them. And you should always have E_ALL (which includes E_NOTICE) turned on. If you have it on and are getting notices, you should fix the code NOT change the level of reported errors. The following code will work and produce what is expected: for ($i = 0; $i < 10; $i++) { $out .= $i . ', '; } print $out; // prints: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, but it will also produce an E_NOTICE the first time through the loop ($out does not exist, but PHP treats it as an empty string and runs on. However, if later on, you modify the code and add the following somewhere ABOVE that: $out = implode(':', range(A-E)); print $out; // prints: A:B:C:D:E then $out is defined going into the for loop and at the end of the for loop it will contain: A:B:C:D:E0, 1, 2, 3, 4, 5, 6, 7, 8, 9, which is probably NOT what you wanted. The correct fix to the for loop is not to turn off E_NOTICE but to define the variable: $out = ''; for ($i = 0; $i < 10; $i++) { $out .= $i . ', '; } print $out; // prints: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and now the code will work correctly even after you come back later and re-use the $out variable elsewhere. Quote Link to comment https://forums.phpfreaks.com/topic/182174-error_reportinge_all-~e_notice/#findComment-961204 Share on other sites More sharing options...
hws Posted November 19, 2009 Author Share Posted November 19, 2009 Sorry guy's. I forgot that error_reporting is php errors, like if you have the wrong syntax in your php script or you are trying to use variables that don't exist. Whereas my error is just part of the contact form php script. He may be messing with me maybe not. 3 computers tried it out and worked fine.....but on his....no. Quote Link to comment https://forums.phpfreaks.com/topic/182174-error_reportinge_all-~e_notice/#findComment-961212 Share on other sites More sharing options...
premiso Posted November 19, 2009 Share Posted November 19, 2009 I guess it depends on what type of error he was seeing. The question is what browser was he using? As far as the error_reporting being on, usually on Development servers it should always be E_ALL, on production display_errors should be off mainly because it can be a security issue and it just does not look professional to have errors shown like that. Plus after testing on Dev you should not have any other problems right? (sarcasm) But as you said, it may not be a PHP error and an error on the Client side IE JScript or HTML which could be caused by a different browser... My bet is, if it is a friend, he is just messing with you. Quote Link to comment https://forums.phpfreaks.com/topic/182174-error_reportinge_all-~e_notice/#findComment-961217 Share on other sites More sharing options...
Daniel0 Posted November 19, 2009 Share Posted November 19, 2009 As far as the error_reporting being on, usually on Development servers it should always be E_ALL, on production display_errors should be off mainly because it can be a security issue and it just does not look professional to have errors shown like that. It should still be set to E_ALL on your production server. You would want your errors to get in the error log. If you disable error reporting it'll just fail silently. What you want to do is set display_errors=off so they won't get printed to the screen. Quote Link to comment https://forums.phpfreaks.com/topic/182174-error_reportinge_all-~e_notice/#findComment-961220 Share on other sites More sharing options...
hws Posted November 19, 2009 Author Share Posted November 19, 2009 Thanks guys.....the error was happening after he submitted a form to the php file. But he may have typed in spaces or so. I have been using ctype_alpha . However, What is the correct one to use if they have spaces in it?? Quote Link to comment https://forums.phpfreaks.com/topic/182174-error_reportinge_all-~e_notice/#findComment-961236 Share on other sites More sharing options...
premiso Posted November 19, 2009 Share Posted November 19, 2009 It should still be set to E_ALL on your production server. You would want your errors to get in the error log. If you disable error reporting it'll just fail silently. What you want to do is set display_errors=off so they won't get printed to the screen. Yea, I think that was what was in my head I just typed it up wrong. Thanks for correcting me though. Quote Link to comment https://forums.phpfreaks.com/topic/182174-error_reportinge_all-~e_notice/#findComment-961281 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.