Question

Server is running PHP5.3. I found the problem by commenting out code until the page run. When I first loaded the page I got no output with no errors.

I set error reporting to:

error_reporting(E_ALL^E_NOTICE);
ini_set('display_errors', 1);

Note: Notices need to be disabled because the system is old and was originally poorly written (something we are resolving now bit by bit)

The line which stopped the script running without errors was this one.

<?php echo explode('cms/', pageURL())[0]?>

This works fine in PHP5.4. It is fine that 5.3 doesn't support this but why doesn't an error display? What is it about this precisely which makes it so difficult to debug? This has happened once or twice for various problems and it would be good to have a better understanding of the underlying issue.

Is it possible to get errors to show on 5.3 with this problem?

Error reporting is working on the server.

poop();

Returns

Fatal error: Call to undefined function poop()

EDIT: While updating the code a failed at editing and had a line which contained this:

$parts = echo explode('cms/',pageURL());

This caused the same problem. No output, no errors. The script just fails.

Was it helpful?

Solution

Background info:

If your error_reporting settings are being setup via function call (not settings files), a syntax error which occurs in the first file being loaded (ex.: index.php) the PHP interpreter can't output the error.

If you have a very simple index.php file which includes the file with the fatal syntax error in it, then the PHP interpreter will be able to output the error.

This is a "known limitation" of the PHP interpreter caused by the fact that most interpreters need to read the file in two passes first to pick up the tokens and then to assess if the tokens correctly represent the language's grammar (allowed order of tokens).

Actually running the code happens after the interpreter finishes these two passes successfully; if it doesn't then all the information the interpreter has is that a syntax error occurred, it doesn't know that you have set error_reporting to some level or another because it considers whatever it read from the file to be "invalid syntax" so it can't run it.

Concrete info:

Since you're using a new syntactic language construct that PHP 5.4 provides but PHP 5.3 doesn't, the legitimate PHP 5.4 construct becomes a syntax error in PHP 5.3.

Having a call to error_reporting in the same file as the syntax error means the function call will not occur and the error level will not be correctly set.

Workaround:

Set your error level by declaring it in your php.ini file or .htaccess file.

OTHER TIPS

Parse errors occur before parsing the file

With the following code:

<?php
error_reporting(E_ALL^E_NOTICE);
ini_set('display_errors', 1);

echo explode('cms/', pageURL())[0]

The code needs to be parsed before the contents are processed. Running with display errors on by default you'd see:

Parse error: syntax error, unexpected '[', expecting ',' or ';' in index.php on line 4

Or similar. If there is a parse error - none of the file is parsed at all, the error is processed before any of the file's contents (which are never processed, as it's a fatal error), and therefore the error reporting settings from before the file was loaded are what applies.

By contrast, this would show the error message:

<?php
error_reporting(E_ALL^E_NOTICE);
ini_set('display_errors', 1);
require 'has_fatal_error.php';

<?php
// has_fatal_error.php;
echo explode('cms/', pageURL())[0]

I'm not sure about this, but it's possible that this particular type of error falls under E_STRICT. In PHP 5.4, E_STRICT is included in E_ALL, but in 5.3 it was not.

Regardless of whether or not this fixes it, it would be prudent to change your error reporting to

error_reporting(E_ALL ^ E_NOTICE | E_STRICT);

If the first file loaded by apache contains parse error, the code is never run.

You need to set in ini file short_open_tag = On after that you will recive the error

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top