-1

I am running into a weird issue with a file include in PHP. This file has a class definition, but when I try to include it in a script, the script terminates at the point of inclusion. Here's an example:

<?php
    require_once('../php_include/twitter_config.php');
    echo 'line '.__LINE__.' executed</br />';
    require_once('../php_include/db_config.php');
    echo 'line '.__LINE__.' executed</br />';
    require_once('../php_include/db_lib.php');
    echo 'line '.__LINE__.' executed</br />';
?>

When I run this script, I always get:

line 3 executed
line 5 executed

And as you can see, I did not create an instance of the class defined in db_lib.php. The IDE I'm using (netbeans) does not seem to think that there are any errors in db_lib.php. Any ideas why this might be happening?

EastsideDev
  • 6,257
  • 9
  • 59
  • 116
  • 3
    we can't help you without knowing the definition in the `db_lib.php` file. – Femaref May 27 '13 at 23:44
  • 1
    Does `db_lib.php` `die()` during execution? – Simon M May 27 '13 at 23:44
  • Have you checked error_log? – Yotam Omer May 27 '13 at 23:45
  • A halted script is probably a fatal error. Don't focus on what your IDE thinks. PHP errors may happen at _runtime_. Turn on error reporting and display errors: `error_reporting(E_ALL); ini_set('display_errors', 1);` (Maybe netbeans executes code, I don't know) – Michael Berkowski May 27 '13 at 23:45
  • Show the `db_lib.php` file. – The Alpha May 27 '13 at 23:47
  • @MichaelBerkowski Netbeans does not execute code. – AbsoluteƵERØ May 28 '13 at 00:45
  • @MichaelBerkowski: netbeans executes code just fine. Make sure your environment is properly set, and that you're running a local Apache server, then do to File.Run. It also WILL provide instant visual feedback if there's an issue with the code (syntax, etc.). The real issue turned out to be that I'm using Google Drive and when it was updating, it changed permissions. When I fixed that, the file opened up just fine. – EastsideDev May 28 '13 at 06:34

1 Answers1

0

This file db_lib.php likely contains an exit() or die() command. If that happens when you run this require the included function is killing the parent file:

require_once('../php_include/db_lib.php');

Also sometimes when an error exists in a file (parse error) with error reporting turned off the page fails to render (leaving a blank page). If your installation of PHP allows overwriting the PHP ini file, then you can use on the page containing the require_once statements:

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

Since you're using a relative require_once statement you might try building the file path appropriately (an example for a directory called php_include in the root folder), in the event that the relative file isn't placed in the relative position the require_once function expects:

require_once($_SERVER['DOCUMENT_ROOT'].'/php_include/db_lib.php');

This path would of course have to be the location for the file above the document root. If the file is outside the document root then you can use the relative folder dots (rare but not unheard of).

require_once($_SERVER['DOCUMENT_ROOT'].'/../php_include/db_lib.php');
AbsoluteƵERØ
  • 7,816
  • 2
  • 24
  • 35