26

When executing a PHP page through browser , we will just get the output but not the errors in code.

how can i view the errors occurred by the code in the backend??

I am using the following in the code for error reporting..

error_reporting(E_ALL | E_ALL);
1

3 Answers 3

61
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);
Sign up to request clarification or add additional context in comments.

3 Comments

I didn't downvote, but why do you have a ^? Isn't that XOR or something? Why do you want to XOR?
@Keoki Zee, display all errors except notice (uninitialized variables etc)... it is the default setting ;)
Okay, that looks ok to me...still don't know why this got downvoted :/
3

Try -1. From the documentation, "Passing in the value -1 will show every possible error, even when new levels and constants are added in future PHP versions."

// Report all PHP errors
error_reporting(-1);

If that doesn't work, try to do an ini_set:

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

17 Comments

And better make the change in the php.ini. Changing the error reporting in a script is useless if the script has syntax errors - it'll be killed long before the error_reporting/ini_set calls ever could get executed.
@webarto: might want to read up on PHP. There is a compile phase, where the raw PHP text you've written is converted into PHP opcodes. It is these opcodes that the various PHP caches (APC) store. The "conversion" is the compile phase.
@webarto: yes, but your php will have error_reporting turned on at the php.ini level, so the errors will be displayed. I'm saying that if you're on a production system, where error_reporting is turned OFF at the .ini level, there is no way for a script with a syntax error to override that to display the compile-time error.
@webarto: Exactly. And if the dashboard's been configured to NOT display the "check engine" light (error_reporting = 0 in the .ini file), there is no way for the car to tell you that there's no engine. Again, you're completely misreading the answer. Most servers have error_reporting turned off at the .ini level. it is IMPOSSIBLE for a script with syntax errors to change that setting at run-time, because there will NEVER BE a runtime. If error_reporting is on, then the syntax error will be reported, but again, the script cannot change the reporting level, because it WILL NOT EXECUTE.
Never mind. It's pointless to argue further. PHP kills scripts at compile time if there's syntax errors, which makes it impossible for the script to do ANYTHING (including change settings via ini_set). Regardless of what you think your test script does, the reality is you're not proving anything.
|
1

Inside your php.ini, set the display_errors to On:

display_errors = On

Then restart your web server.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.