Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/182174-error_reportinge_all-~e_notice/
Share on other sites

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);

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.

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.

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.

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.

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.

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.