Parse errors are not displayed

泄露秘密 提交于 2019-11-29 09:09:06

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!

Travis

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!