Search code examples
phpdebuggingrequirerequire-once

PHP - Debugging Require


I am having some problems using require or require_once in that the code halts execution after the call and I am struggling to find what exactly is causing the problem.

I have checked the file exists and can be read (via file_exists and is_readable) but both of these appear to be true so I am a little stumped.

require_once('file1.php');
print('a');
$file = 'file2.php';
if (!file_exists($file)) { die('file does not exist'); }
if (!is_readable($file)) { die('cannot read file'); }
require_once($file);
print('b');

Above code outputs only 'a' and nothing after.

Another file on the server uses both of the files in question in the same way without problem.

Is there anything else I could check?

Any help would be appreciated.

Edit:

Setting error_reporting(E_ALL) does not change the output.

Changing the file path to a blank file in the same directory changes the output to 'ab', indiciating the require has worked and suggesting their is a problem with file2.php, however another file on the server successfully uses these file in the exact same manner.

Running php -l for file2.php returns no errors.

Commenting out the first require makes no difference.

Edit2:

Problem was to do with a call to class_exists and the change in behaviour in version 5.0 to do with auto loading. The code in question was wrote before upgrade to 5.0.


Solution

  • Set error_reporting(E_ALL) and try to include an empty file instead of file2.php.

    Maybe file2.php has some bug that halts the flow