/    Sign up×
Community /Pin to ProfileBookmark

What will show error report?

What will show
error report like:

[code=php]
ini_set(‘error_reporting’, E_ALL)
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 10.2009 — I'm not really sure what the question is here, but if you want your script to display all run-time errors:
[code=php]
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
[/code]

Note that if display_errors is turned off by the PHP configuration, then parse errors still will not be displayed, as they are generated [i]before[/i] any code - including the above - is actually executed by the script.
Copy linkTweet thisAlerts:
@toplisekauthorFeb 11.2009 — Have few poits:

1. So error_reporting(0); will block displaying all errors mesage even this code is at the top?

2. How to avoid that there will be shown any secret path, values when showing errors in correct way?
Copy linkTweet thisAlerts:
@NogDogFeb 11.2009 — Generally speaking, your production (i.e. "live") host environment should have [b]display_errors[/b] turned off so that no PHP error messages get displayed, both for security and because it looks bad. You should have the [url=http://www.php.net/manual/en/errorfunc.configuration.php#ini.log-errors]log_errors[/url] turned on and the [url=http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-log]error_log[/url] setting pointing to the desired log file so that you can review it for errors. [b]error_reporting[/b] should then still be set at a high enough level to see all errors [i]in that log file[/i] that you might be interested in (I'd normally suggest leaving it at [b]E_ALL[/b], or [b]E_ALL & ~E_NOTICE[/b] if you have sloppy code that generates lots of notices, but hopefully you don't ? ).

In any case, you should not depend on the built-in error reporting in any way for your application: such errors indicate a fault in the code, not a user error. You should be writing defensive code that prevents such errors from happening.

Bad:
[code=php]
$result = mysql_query($sql) or die(mysql_error() . "<br />n$sql");
while($row = mysql_fetch_assoc($result)) {
[/code]

Better:
[code=php]
$result = mysql_query($sql);
if($result == false)
{
error_log(mysql_error()."n$sql");
echo "<p class='error'>Sorry, there was a database error which has been logged.</p>";
}
else
{
while($row = mysql_fetch_assoc($result) {
// etc...
}
[/code]
×

Success!

Help @toplisek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...