error_reporting(E_ALL) does not produce an error - php

This is my PHP script -
<?php
error_reporting(E_ALL);
echo('catch this -> ' ;. $thisdoesnotexist);
?>
Which obviously should show something if it were to be executed.
All I see is an empty page. Why is error_reporting(E_ALL) not working?
<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
echo('catch this -> ' ;. $thisdoesnotexist);
?>
Does not help either. All I get is an empty page.
I've been to php.ini and set display_errors = On and display_startup_errors = On. Nothing happens.

Your file has a syntax error, so your file was not interpreted, so settings were not changed and you have a blank page.
You can separate your file in two:
File index.php
<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
include 'error.php';
File error.php
<?
echo('catch this -> ' ;. $thisdoesnotexist);

That error is a parse error. The parser is throwing it while going through the code, trying to understand it. No code is being executed yet in the parsing stage. Because of that it hasn't yet executed the error_reporting line, therefore the error reporting settings aren't changed yet.
You cannot change error reporting settings (or really, do anything) in a file with syntax errors.

In your php.ini file check for display_errors. I think it is off.
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

In your php.ini file check for display_errors. If it is off, then make it on as below:
display_errors = On
It should display warnings/notices/errors.
Please read error_reporting int.

You can try to put this in your php.ini:
ini_set("display_errors", "1");
error_reporting(E_ALL);
In php.ini file also you can set error_reporting();.

Turn on display errors in your ini file:
display_errors string

Just do the following:
Check phpinfo();. Check if display_errors is on or off
If it is On, just add error_reporting(E_ALL); in your primary index file.
If it is Off, just add it in your primary index file
ini_set("display_errors", "1"); // This is the instant setup for individual applications
error_reporting(E_ALL);
then check phpinfo();. Check display_errors. Now it is on, which is only for this application
then create any code error for testing and reload the page
Hurray! Now you can see the errors in your console. If the errors are not displaying in your console and the page loading failed with a red alert in network, don't worry.
Check if you have enabled modsecurity and it has any rule checking is written in SecRule for PHP. Remove that secrule or disable the modsecurity for your development period.

Related

Not displaying errors in php

I am debugging some errors in my PHP bus booking site. My issue is that I am not able to display errors. When I googled this issue it shows you can achieve it though php.ini. But unfortunately I haven't find any php.ini file .
Now the error is showing as
This page isn’t working
cableandmedia.com is currently unable to handle this request. HTTP
ERROR 500
On your all-pages/or-a-common-file which-is-included-in-each-file.
On top just after starting <?php add these two lines:-
error_reporting(E_ALL);
ini_set('display_errors',1);
If you have php.ini file then check these two variables:-
display_errors
error_reporting
Now change these variables values to:-
display_errors=ON
error_reporting=E_ALL
Now save the file and restart your server(important if you are working on localhost).And you have good to go.
Add this line to your php file. To debug
ini_set('display_errors', 1);
error_reporting(E_ALL);

No detailed error messages

I am getting internal server error when calling php script via ajax. I set ini_set("display_errors", 1); error_reporting(E_ALL); but still no details .. what else should I do
inside your php.ini the
display_errors = On
The php.ini file is where base settings for all php on your server, however these can easilybe overridden and alterd any place in the PHP code and affect everything following that change. This happens a in frameworks. A good check is to add the display_errors to you php.ini. If you don't see an error, but one is being logged, insert this at the top of the file causing the error:
ini_set('display_errors', 1);
error_reporting(E_ALL);
If this works then something earlier in your code is disabling error display.

PHP does not always display an error when there is clearly an error

I'm experiencing a weird issue where errors are not being displayed when there are obvious errors.
This throws an error as expected:
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
hurrrrr
?>
However, this does not and just returns a blank page...
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
HUUURRRR
include('../includes/simple_html_dom.php');
$html = file_get_html('www.hurrrr.com');
foreach($html->find('.Hurrrrrrr') as $element) {
echo $element->plaintext . '<br />';
}
?>
PHP is run in two main "passes".
Parse the code.
Run the code.
If the code cannot be parsed (hurrrrr), then it cannot be run.
If it cannot be run, then display_errors and error_reporting cannot be set.
If they cannot be set, then errors cannot be shown.
This is why it is preferable to set these in your php.ini file (or whatever configuration file is used for your setup). Indeed display_startup_errors cannot be set via ini_set() because by the time ini_set is called, startup has already finished!
You have to change the display_errors settings in php.ini.
If you are in localhost and use WAMP, right-clicking on WAMP icon and selecting php.ini may not solve your problem, as you should go to your wamp/bin/php*/php.ini and change this file.

Not getting PHP errors?

For some reason on this particular script, which is a copy of a script I use in a lot of other places, I am not getting any PHP errors. It simply shows a blank page, and It took me a long long time to hunt down a missing semi-colon this morning. Why arn't errors showing up?
my PHP.INI for this sub-domain:
display_errors = On
short_open_tag = On
memory_limit = 32M
date.timezone = Europe/Paris
The code at the top of the page:
session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');
The Sub Domain is set to run PHP as an Apache Module Which is the same as every other domain I use.
So I am not sure why I am not getting errors displayed. Can anyone tell me?
EDIT:
This is solved, because the errors I was producing were on the page where I had got the lines:
error_reporting(E_ALL);
ini_set('display_errors', '1');
written. When I put the error on to a seperate page and included it, I could see the error fine.
I guess that's why they use bootstrapping!
You should set error_reporting to E_ALL in the php.ini as well: when a parse error occurs (such as a missing semicolon), your error_reporting(E_ALL) won't be used.
You could try to change this lines to get more information from php:
; The display of errors which occur during PHP's startup sequence are handled
; separately from display_errors. PHP's default behavior is to suppress those
; errors from clients. Turning the display of startup errors on can be useful in
; debugging configuration problems. But, it's strongly recommended that you
; leave this setting off on production servers.
display_startup_errors = On
; When PHP displays or logs an error, it has the capability of formatting the
; error message as HTML for easier reading. This directive controls whether
; the error message is formatted as HTML or not.
; Note: This directive is hardcoded to Off for the CLI SAPI
html_errors = On
error_reporting(E_ALL);
ini_set('display_errors',1);
ini_set('display_startup_errors',1);

PHP does not display error messages

I installed XAMPP 1.7.4 (with PHP 5.3.5), the problem is PHP does not display any error messages. E.g. if I connect to MYSQL with mysql_connect() without parameters, PHP will not complain about the required fields.
Why is this?
How can I configure PHP to display errors?
To turn on errors at the script level, include at the top of your script:
ini_set('display_errors', 1);
error_reporting(~0);
Alternatively, if it is not a production site and simply a development / testing site, you can turn on error reporting in php.ini. Search it for these settings:
error_reporting = E_ALL
;error_reporting = E_ERROR
display_errors = On
;display_errors = Off
May be the display error is off
add in .htaccess file of your application.
php_value display_errors on
OR
use this at the top of your php script
ini_set('display_errors',"1");
To show error message on page over browser for php script use following code in top of your php file.
<?php
ini_set('display_errors', 1);
error_reporting(~0);
?>
and there is another way to check php error code if you are linux ubuntu user execute following command on terminal.
NOTE : -10 is the number of message you want to show.
It possibly did override your settings in the php.ini. Check the php.ini for error handling parameters and make sure they're switched on.
Happened to me a few weeks ago, too
You can use following code in your program
error_reporting(E_ALL);
ini_set('display_errors', '1');

Categories