Parse errors are not displayed - php

I want PHP to display parse errors on screen. What I get instead is a blank page. Nothing gets written to server's error log file.
My setup: PHP5.2.9/IIS 6 (not Apache!).
My PHP.INI:
error_reporting=E_STRICT
display_errors = On
display_startup_errors = On
log_errors = On
error_log = "C:\Program Files\Zend\ZendServer\logs\php_error.log"
How do I get parse or fatal errors to be either logged or shown on screen?
Thanks,
Temuri
UPDATE: After playing with different switches it looks to be an IIS specific problem. ANY IDEAS FOLKS?

Setting error level in php file itself does not resolve the problem here because the file itself cannot be parsed !!
You need to change error_reporting line in your php.ini as follows:
error_reporting = E_ALL
BTW: There are some examples in php.ini file about what to do to display which type of error messages.
Good luck,
mcemoz

Apache doesn't always like to report parsing errors either. From the command line, run
php -l <file>
The -l switch tells PHP to check file syntax. See the man page.

E_STRICT is not included in E_ALL (until PHP 6). If you want to keep getting E_STRICT
In php.ini:
error_reporting = E_ALL | E_STRICT
At runtime:
error_reporting( E_ALL | E_STRICT );
You'll need to set the error reporting level (and display_errors) in php.ini to see syntax errors. If PHP encounters a syntax error, the runtime doesn't get executed, so setting at runtime won't work. (See the display_errors link.)

You can verify the script syntax with this command in terminal:
php -l path/to/file.php
Personally, I added this line to my ~/.bash_profile file so I can easily run php -l on all files in the current working directory:
phpl() { for i in *.php; do php -l $i; done }
If you're really hardcore, you can even run your app from the command line. You'll have a much better chance of seeing compile-time errors, and it's just kinda cool.
You can use the $argv variable to get the first argument, $argv[1], then use that as the request.
<?php
// show those errors!
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
// simulate a web server request
$request = '/' . isset($argv[1]) ? ltrim($argv[1], '/') : '/';
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'] = $request;
Then you can run your script via command line. This would be the equivalent of visiting:
your-webapp.com/request/uri/here
php /path/to/script.php request/uri/here
Here is a more comprehensive example for running CodeIgniter via command line. It should work for many other frameworks too: http://phpstarter.net/2008/12/run-codeigniter-from-the-command-line-ssh/

As Rasmus Lerdorf suggests, always use error_reporting(-1) on development server.

Re: Blank screen of php death death, I discovered that setting
php_value error_reporting "E_ALL" or
php_value error_reporting 8192
in .htaccess on my Windows 7, Wampserver w/ apache 2.2.4 and php 5.3.13 are sure ways to get the blank php error screen -- today, June 3, 2014. These htaccess lines DO set the desires value in phpinfo(), but the display of the errors happens only when the line is commented out (not used) in htaccess.
BUT... the next minute I discover that
php_value error_reporting 8191
DOES set the phpinfo() value AND also allows display of the error messages to the browser! D'oh! It must be an integer and also apparently a particular or valid integer, and not just a large enough integer!

If you're using Zend Framework (v1) and you're using the Autoloader, the following code will prevent parse errors from being displayed:
self::$Autoloader->suppressNotFoundWarnings(true);
See the following answer for more details:
Display php errors when using Zend framework

Try this.
error_reporting(E_ALL);
ini_set("display_errors", 1);

Related

Print error in file php on PC

I'm new in PHP. I run file.php on my PC with Firefox but I don't know how see error. What I can add to see it, is possible if I have this file on pc and not on server?
Maybe this:
error_reporting(E_ALL);
ini_set('display_errors', 1);
or it works only on Apache?
I tried nothing because I don't know how solve it.
This my file.php
<?php
include('wrapper.php');
$apikey = "xxx7d7391d1e68e9680e6";
voxmail_init($apikey);
voxmail_user_subscribe(array('mail' => 'xxxxx#gmail.com','privacy' => 1));
?>
This file used api newsletter service (the code - for assistance of service - is ok) and voxmail_user_subscribe register the email address at newsletter. wrapper.php is file in same folder of file.php for use API of this service.
In this wrapper.php is there include other file xmlrpc.inc (also in same folder)
Now when I run file.php in my browser the only thing that I see is this:
**'xxxx#gmail.com','privacy' => 1));?>**
but the assistant servec tried my code and works... he ask me to show error log, but I don't know where is this log.
Those directives can be set in lots of different places, as explained at Runtime Configuration. You need to be aware of the different syntaxes:
If you set them from PHP code, you have to compose valid PHP code, e.g.:
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
If you set it in PHP configuration files (php.ini or .user.ini) you have to use valid *.ini syntax:
error_reporting = E_ALL
display_errors = On
If you set it in Apache configuration files (httpd.conf or .htaccess) you have to use valid apache syntax:
php_value error_reporting E_ALL
php_flag display_errors On
It's worth noting that errors that prevent PHP code from running (such as parse errors) cannot be set from within PHP code.
My advice is to configure your local system-wide file for development (display all errors, log none) and configure your project for dual configuration (display in development, log in production).
Answer to updated question:
can't see any obvious reason why your code should trigger errors and notices. Are you sure it does? Have you tried with something that should trigger one such as 1/0;?
If you can see PHP code in the browser, your code is not running at all.
Example
error_log("You messed up!", 3, "/var/tmp/my-errors.log");
You can use
error_log — Send an error message somewhere

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);

How to have PHP display errors? (I've added ini_set and error_reporting, but just gives 500 on errors)

So, I don't really have any errors in my current web page, but I want to be able to see an error when they pop up, instead of the HTTP 500 error page. I googled around a bit and thought adding these two lines would fix everything.
ini_set('display_errors', 'On');
error_reporting(E_ALL);
NOTE: I don't have access to the php.ini file, as I'm using my school account's server.
So I introduced a bug (no semicolon after $buggy) like so at the top of my page:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$buggy
$x = 4 + 2;
...
However, I just get a Server error:
"The website encountered an error while retrieving http://mywebpage.com/. It may be down for maintenance or configured incorrectly."
Any ideas?
EDIT:
I've reconfigured my code:
<?php
include_once 'database/errorSettings.php';
?>
<?php
$buggy // whoops
$x = 4 + 2;
...
errorSettings.php is the following:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
?>
But it still doesn't work... wrong way to reconfigure?
What you have is a parse error. Those are thrown before any code is executed. A PHP file needs to be parsed in its entirety before any code in it can be executed. If there's a parse error in the file where you're setting your error levels, they won't have taken effect by the time the error is thrown.
Either break your files up into smaller parts, like setting the error levels in one file and then includeing another file which contains the actual code (and errors), or set the error levels outside PHP using php.ini or .htaccess directives.
You need to set the error_reporting value in a .htaccess file. Since there is a parse error, it never runs the error_reporting() function in your PHP code.
Try this in a .htaccess file (assuming you can use one):
php_flag display_errors 1
php_value error_reporting 30719
I think 30719 corresponds to E_ALL but I may be wrong.
Edit Update: http://php.net/manual/en/errorfunc.constants.php
int error_reporting ([ int $level ] )
---
32767 E_ALL (integer)
All errors and warnings, as supported, except of level E_STRICT prior to PHP 5.4.0. 32767 in PHP 5.4.x, 30719 in PHP 5.3.x, 6143 in PHP 5.2.x, 2047 previously
Adding to what deceze said above. This is a parse error, so in order to debug a parse error, create a new file in the root named debugSyntax.php. Put this in it:
<?php
/////// SYNTAX ERROR CHECK ////////////
error_reporting(E_ALL);
ini_set('display_errors','On');
//replace "pageToTest.php" with the file path that you want to test.
include('pageToTest.php');
?>
Run the debugSyntax.php page and it will display parse errors from the page that you chose to test.
Just write a following code on top of PHP file:
ini_set('display_errors','on');
Syntax errors is not checked easily in external servers, just runtime errors.
What I do? Just like you, I use
ini_set('display_errors', 'On');
error_reporting(E_ALL);
However, before run I check syntax errors in a PHP file using an online PHP syntax checker.
The best, IMHO is PHP Code Checker
I copy all the source code, paste inside the main box and click the Analyze button.
It is not the most practical method, but the 2 procedures are complementary and it solves the problem completely
I have had this problem when using PHP5.4 and Plesk 11.5
Somehow, the error reporting and display error settings in the Plesk domain configuration page were completely overriding any local settings in .htaccess or the PHP scripts. I have not found a way to prevent this happening, so use the Plesk settings to turn error reporting on and off.
You may have settings in your php.ini that prevents the local site from overriding these settings, perhaps enforced by the control panel used on your server.
To people using Codeigniter (i'm on C3):
The index.php file overwrite php.ini configuration, so on index.php file, line 68:
case 'development':
error_reporting(-1);
ini_set('display_errors', 1);
break;
You can change this option to set what you need. Here's the complete list:
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
6143 E_ALL
2048 E_STRICT
4096 E_RECOVERABLE_ERROR
Hope it helps.

Error logging with WAMP server in PHP

I have a WAMP 2.2 server running on a Windows 7 box and cannot get PHP error logging working at all.
The file is always blank even after I explicitly trigger USER_ERROR errors, or cause normal ERROR errors.
I'm including the error relevant sections of the php.ini file - hopefully you can find something:
error_reporting = E_ALL
error_log = "c:/wamp32/logs/php_error.log" ;(UNCOMMENTED BY ME)
log_errors = On
display_errors = On
The line ; log_errors is just a comment for the following block, for the purpose of showing you what the settings are in dev vs production. You uncommented four lines which aren't meant to control anything, and I'm surprised your Apache service doesn't have problems starting up because of it.
What you need to do is look for the line:
log_errors = Off
And change the value to On
That said, once you restart the Apache service, the settings should take effect. However, I was unable to get WampServer to properly log php errors despite these settings. Apache will not start up when I specify the error_log parameter.
For me it turned out to be a permissions error. I ended up giving EVERYONE full control of the error log file and it seemed to fix my issue. Best of luck.
Did you try adding these lines to your php file?
ini_set("display_errors", "1");
ini_set("log_errors", "1");
ini_set("error_log", "/wamp64/logs/php_error.log");

XAMPP does not display php errors

I have installed xampp on ubuntu. PHP is configured to show all possible errors, warnings, notices etc, but when i make an error in php code no error is displayed.
When i copy that file to other computer (debian with native apache, mysql and php set) and open it in browser it shows
Fatal error: Call to a member function fetch() on a non-object in...
as expected, so why xampp with identical php.ini shows just an empty page?
Another solution is
add this line in your .htaccess file
php_value display_errors on
there may be some serever configure mistake
write below as first line at your php page
ini_set('error_reporting', E_ALL);
ini_set( 'display_errors', 1 );
NOTE: use Xdebug
Find your php.ini file. You can find the location by typing php --ini in the terminal.
Then look for display_errors and set it to 1. And error_reporting to E_ALL.
This will set the value globally.
If you only need to see errors for a particular script or application:
error_reporting( E_ALL );
ini_set( 'display_errors', 1 );
http://php.net/manual/en/function.error-reporting.php
http://php.net/manual/en/errorfunc.configuration.php

Categories