I have updated my PHP version 5.3 to 5.5 and currently it starts to display internal server error instead of showing errors.
My php.ini settings configurations are as below:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
I have already trial-and-error'ed various options available at stack overflow:
error_reporting = E_ALL
error_reporting = E_NOTICE
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
Try to set display_errors to On in your php.ini. See http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors.
With reference http://www.php.net/manual/en/errorfunc.configuration.php and fnc, I have used in two ways as given below, both of them work fine at my end.
Option 1: Add the following line at the end of php.ini file or change value if it is existed as:
display_errors = On
Option 2: Change settings run time, add below line at the top of PHP script file.
<?php
if (!ini_get('display_errors')) {
ini_set('display_errors', '1');
}
?>
Related
I know what the error_reporting values mean. I know -1 means "show all" and 0 means "show none".
But nowhere is specified what is the value set by default, when nothing is specified by the user.
Trying phpinfo() I see
...
Configuration File (php.ini) Path => /usr/local/etc/php
Loaded Configuration File => (none)
...
So, given there's no php.ini loaded, what is the default value/behaviour of error_reporting?
From the documentation of the config file options
The default value is E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED. This setting does not show E_NOTICE, E_STRICT and E_DEPRECATED level errors. You may want to show them during development.
In PHP 8.0, the default changed to E_ALL. See https://php.watch/versions/8.0/error-display-E_ALL
In PHP 5.3 or newer versions but prior to PHP 8.0, the default error_reporting level was:
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
This means that all type of errors are reported except E_NOTICE,
E_STRICT, and E_DEPRECATED.
Since PHP 8.0, the default error_reporting level is E_ALL.
error_reporting = E_ALL
Have a look: https://lindevs.com/default-error-reporting-level-is-e_all-in-php-8-0/
I've inherited some code that is working great on one server, which is running PHP 7.1.7. Throughout the code their are numerous if statements similar to the following that are checking to see if a variable exists.
if ($_SESSION['user'])
if ($_POST['company_id'])
On the new server, which as PHP 7.2.5, these if statements are throwing errors. I'm having to change them all to use "empty".
if (empty($_SESSION['user']))
if (!empty($_POST['company_id']))
This wouldn't be a big deal if there were only a few, but there's 100+. I've tried changing the PHP version to 7.1.7 on the new server to match the old, but still have the same issue.
I have to imagine there is a setting somewhere that could be changed to allow these work without the need to use "empty" on all of them. Thanks for any insight.
Like #IncredibleHat suggested, you can prevent this by suppressing error notices. Any one of these three should address the warnings.
// this can go in your PHP
ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
// OR you can put this in your .htaccess file
php_value error_reporting E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
// OR you can put this in your php.ini file
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
I am working on project # home and using WAMP for development. Currently the php.ini file has the following lines set like this:
error_reporting = E_ALL & ~E_DEPRECATED
display_errors = On
I had hoped in doing so it would prevent deprecation warnings from showing up. However it is not. Is there a way I can adjust error_reporting to ignore deprecated warnings.
Output I am getting currently:
You can use this function :
error_reporting(E_ALL ^ E_DEPRECATED);
http://www.php.net/manual/en/function.error-reporting.php
Or use "#" operator before function name.
#mysql_connect();
In your php.ini file change the following.. (note wamp has 2 different php.ini files so make the changes on both)
from this
error_reporting = E_ALL
to this
error_reporting = E_ALL & ~E_DEPRECATED
I had the same problem. It turned out however, that I edited wrong php.ini file. In my case the correct one was
C:\wamp64\bin\php\php5.6.25\phpForApache.ini
and in this file I have changed this line to:
error_reporting = E_ALL & ~E_DEPRECATED.
It didn't make any difference what I had changed in that "obvious" php.ini file.
Set your error report to
error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
on your php page.
If you want to show all errors except deprecated, then use this setting:
error_reporting = E_ALL ^ E_DEPRECATED
Edit: You could also create a custom error handler to hide only mysql_ deprecation warnings:
set_error_handler(function($errno, $errstr) {
return strpos($errstr, 'mysql_') === 0;
}, E_DEPRECATED);
But please note that mysql_ functions are deprecated. So instead of trying to hide the errors, consider switching to mysqli or PDO.
To hide php errors on WAMP server, Please open php.ini file and find following line of code
error_reporting = E_ALL
and replace it with
error_reporting = E_ALL & ~E_NOTICE
All errors will be hide/disable.
I cant enable displaying php errors ...At the end I just put defaults and sharing it here
with hope to get some help .. In addition , when I add following piece of code to the php file errors become enabled :
ini_set('display_errors', 1);
ini_set('html_errors', 1);
error_reporting(E_ALL);
Furthermore after adding that code, it still doesnt show syntactic errors
(for example typing "whle" instead of "while")
However, I cant figure out how to make these changes through php.ini :
; display_errors
; Default Value: On
; Development Value: On
; Production Value: On
; display_startup_errors
; Default Value: Off
; Development Value: On
; Production Value: Off
; error_reporting
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
Adding
ini_set('display_errors', 1);
ini_set('html_errors', 1);
error_reporting(E_ALL);
to a file will not work if there are syntax errors in the file as the parser finds the error before the code is run, so the error stops it turning errors on
Editing /etc/php5/cli/php.ini will not work as all you have done is add comments to the file
You would need to uncomment the setting ie remove the ; from in front of it)
display_errors = on
It is also possible that /etc/php5/cli/php.ini is not the right file to edit depending on how your system is configured as Phil has said in comments
<?php phpinfo() ?>
will show you which php file you need to edit and if it is accessed via a webserver eg apache, then you may need to restart your webserver before any changes to that file take effect
you should have
error_reporting = E_ALL
display_errors = On
html_errors = On
in your php.ini file for the php code you are using
Here is my php.ini and I have restarted the httpd process several times while messing around with this, however no errors are being displayed, only a blank page.
error_reporting = E_ALL & E_STRICT
display_errors = On
In dev, we use this:
error_reporting = E_ALL | E_STRICT