2

My setup is as follows:

/index.php  
/php/init.php  
/php/config.php  
/php/functions.php

The very first thing index.php does is:

<?php include 'php/init.php'; ?>  

init.php then goes on like this:

<?php  
define('DEBUG',true);   
if(DEBUG){          
error_reporting(E_ALL);  
ini_set('display_errors', '1');  
}  
require_once 'config.php';  
require_once 'functions.php';   
?>

When the page is loaded, I get a bunch of errors from functions.php, complaining about missing variables that should have been set in config.php. Turns out, everything within config.php is simply ignored as if the require_once statement wasn't there. var_dump( get_included_files()); confirms this.

It does not display any errors, and if I simply replace the require_once line with the content of config.php, it works perfectly fine. The same thing also happens when both config.php and functions.php contain nothing more than a single echo command. So the contents of the files should not be an issue in this. I'm a bit out of ideas on how to determine where the error is and why it would include one file, but not the other.

Can anyone help?

C.Funken
  • 51
  • 5
  • Without seeing the contents of your functions and config it's not possible to comment. Also, it's most likely that you are confusing/misusing the scope of variables. – Layke Oct 16 '12 at 10:36
  • Where are you including `config.php`? In `index.php` or in `php/init.php`? – Passerby Oct 16 '12 at 10:37
  • Sorry for being unclear, I've edited it to be more precise. Basically: it's included in the init.php and the contents of config and functions don't factor into the error. I've replaced them both with echo's and nothing changes. – C.Funken Oct 16 '12 at 11:31

1 Answers1

3

Is this code

_<_?php  
define('DEBUG',true);   
if(DEBUG){          
error_reporting(E_ALL);  
ini_set('display_errors', '1');  
}  
require_once 'config.php';  
require_once 'functions.php';   
?>

belongs to index.php

if this is the case, your config and function paths are not correct.

use

require_once 'php/config.php';  
require_once 'php/functions.php';

instead of

require_once 'config.php';  
require_once 'functions.php';

I guess this will solve your problem.

Ravi
  • 2,078
  • 13
  • 23
  • `require_once __DIR__ . '/config.php';` is perhaps a nicer way to do it. Then it'll still work if you change the directory. If your PHP version is < 5.3 then you'll want to use `dirname(__FILE__);` instead of `__DIR__` though. – RobMasters Oct 16 '12 at 10:41
  • Nope. The code is from init.php. Sorry if that wasn't clear from the text. – C.Funken Oct 16 '12 at 11:33
  • Try using this code `` – Ravi Oct 16 '12 at 12:16
  • I add that this should be added to every single file you wish to debug: for example if "error_reporting(E_ALL); ini_set('display_errors', '1'); " are set only once in the main project's config I found that could happen that you get blank pages without being notified of any errors. Worked for me for a Joomla project, hope this helps someone else. Linuxatico – linuxatico Sep 11 '13 at 07:40