- This topic is empty.
-
AuthorPosts
-
June 27, 2009 at 7:09 am #10156absParticipant
I have checked my PHP ini file (
php.ini
) anddisplay_errors
is set and also error reporting isE_ALL
. I have restarted my Apache webserver.I have even put these lines at the top of my script, and it doesn’t even catch simple parse errors. For example, I declare variables with a
"$"
and I don’t close statements";"
. But all my scripts show a blank page on these errors, but I want to actually see the errors in my browser output.error_reporting(E_ALL); ini_set('display_errors', 1);
What is left to do?
June 27, 2009 at 7:14 am #10182michael-madsenParticipantYou can’t catch parse errors in the same file where error output is enabled at runtime, because it parses the file before actually executing anything (and since it encounters an error during this, it won’t execute anything). You’ll need to change the actual server configuration so that display_errors is on and the approriate error_reporting level is used. If you don’t have access to php.ini, you may be able to use .htaccess or similar, depending on the server.
This question may provide additional info.
January 8, 2013 at 9:27 am #10181user1803477ParticipantInside your php.ini:
display_errors = on
Then restart your web server.
May 18, 2013 at 3:01 am #10179kalhuaParticipantSome web hosting providers allow you to change PHP parameters in the
.htaccess
file.You can add the following line:
php_value display_errors 1
I had the same issue as yours and this solution fixed it.
January 29, 2014 at 9:52 am #10180andreParticipantTo display all errors you need to:
1. Have these lines in the PHP script you’re calling from the browser (typically
index.php
):error_reporting(E_ALL); ini_set('display_errors', '1');
2.(a) Make sure that this script has no syntax errors
—or—
2.(b) Set
display_errors = On
in yourphp.ini
Otherwise, it can’t even run those 2 lines!
You can check for syntax errors in your script by running (at the command line):
php -l index.php
If you include the script from another PHP script then it will display syntax errors in the included script. For example:
index.php
error_reporting(E_ALL); ini_set('display_errors', '1'); // Any syntax errors here will result in a blank screen in the browser include 'my_script.php';
my_script.php
adjfkj // This syntax error will be displayed in the browser
January 29, 2014 at 11:25 am #10183fancy-johnParticipantDEV environment
This always works for me:
ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL);
However, this doesn’t make PHP to show parse errors occurred in the same file. Also, these settings can be overridden by PHP. In these cases the only way to show those errors is to modify your php.ini (or php-fpm.conf) with this line:
display_errors = on
(if you don’t have access to
php.ini
, then putting this line in.htaccess
might work too):php_flag display_errors 1
PROD environment
Note that above recommendation is only suitable for the DEV environment. On a live site it must be
display_errors = off log_errors = on
And then you’ll be able to see all errors in the error log. See Where to find PHP error log
AJAX calls
In case of AJAX call, on a DEV server, open DevTools (F12), then Network tab.
Then initiate the request which result you want to see, and it will appear in the Network tab. Click on it and then the Response tab. There you will see the exact output.While on a live server just check the error log all the same.
May 5, 2014 at 1:23 am #10176mahendra-jellaParticipantThis will work:
<?php error_reporting(E_ALL); ini_set('display_errors', 1); ?>
March 31, 2015 at 6:38 am #10173navyakumarParticipantCreate a file called php.ini in the folder where your PHP file resides.
Inside php.ini add the following code (I am giving an simple error showing code):
display_errors = on display_startup_errors = on
April 24, 2015 at 2:55 am #10171jxmallettParticipantIf, despite following all of the above answers (or you can’t edit your php.ini file), you still can’t get an error message, try making a new PHP file that enables error reporting and then include the problem file. eg:
error_reporting(E_ALL); ini_set('display_errors', 1); require_once('problem_file.php');
Despite having everything set properly in my
php.ini
file, this was the only way I could catch a namespace error. My exact scenario was://file1.php namespace a\b; class x { ... } //file2.php namespace c\d; use c\d\x; //Dies because it's not sure which 'x' class to use class x { ... }
January 11, 2016 at 12:11 pm #10169chiborgParticipantIf you somehow find yourself in a situation where you can’t modifiy the setting via
php.ini
or.htaccess
you’re out of luck for displaying errors when your PHP scripts contain parse errors. You’d then have to resolve to linting the files on the command line like this:find . -name '*.php' -type f -print0 | xargs -0 -n1 -P8 php -l | grep -v "No syntax errors"
If your host is so locked down that it does not allow changing the value via
php.ini
or.htaccess
, it may also disallow changing the value viaini_set
. You can check that with the following PHP script:<?php if( !ini_set( 'display_errors', 1 ) ) { echo "display_errors cannot be set."; } else { echo "changing display_errors via script is possible."; }
March 28, 2016 at 7:26 am #10178frank-forteParticipantWarning: the below answer is factually incorrect. Nothing has been changed in error handling, uncaught exceptions are displayed just like other errors. Suggested approach must be used with caution, because it outputs errors unconditionally, despite the display_error setting and may pose a threat by revealing the sensitive information to an outsider on a live site.
You might find all of the settings for "error reporting" or "display errors" do not appear to work in PHPÂ 7. That is because error handling has changed. Try this instead:
try{ // Your code } catch(Error $e) { $trace = $e->getTrace(); echo $e->getMessage().' in '.$e->getFile().' on line '.$e->getLine().' called from '.$trace[0]['file'].' on line '.$trace[0]['line']; }
Or, to catch exceptions and errors in one go (this is not backward compatible with PHPÂ 5):
try{ // Your code } catch(Throwable $e) { $trace = $e->getTrace(); echo $e->getMessage().' in '.$e->getFile().' on line '.$e->getLine().' called from '.$trace[0]['file'].' on line '.$trace[0]['line']; }
May 4, 2016 at 7:14 am #10177abhijit-jagtapParticipantUse:
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
This is the best way to write it, but a syntax error gives blank output, so use the console to check for syntax errors. The best way to debug PHP code is to use the console; run the following:
php -l phpfilename.php
January 13, 2017 at 6:56 am #10162jewelhuqParticipantJust write:
error_reporting(-1);
February 1, 2017 at 7:16 am #10172channaveer-hakariParticipantI would usually go with the following code in my plain PHP projects.
if(!defined('ENVIRONMENT')){ define('ENVIRONMENT', 'DEVELOPMENT'); } $base_url = null; if (defined('ENVIRONMENT')) { switch (ENVIRONMENT) { case 'DEVELOPMENT': $base_url = 'http://localhost/product/'; ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); break; case 'PRODUCTION': $base_url = 'Production URL'; /* https://google.com */ error_reporting(E_ALL); ini_set('display_errors', 0); ini_set('display_startup_errors', 0); ini_set('log_errors', 1); // Mechanism to log errors break; default: exit('The application environment is not set correctly.'); } }
February 1, 2017 at 7:33 am #10170binit-ghetiyaParticipantYou can do something like below:
Set the below parameters in your main index file:
ini_set('display_errors', 1); ini_set('display_startup_errors', 1);
Then based on your requirement you can choose which you want to show:
For all errors, warnings and notices:
error_reporting(E_ALL); OR error_reporting(-1);
For all errors:
error_reporting(E_ERROR);
For all warnings:
error_reporting(E_WARNING);
For all notices:
error_reporting(E_NOTICE);
For more information, check here.
-
AuthorPosts
- You must be logged in to reply to this topic.