The way PHP handles includes is very weird, for example:

- create a folder, name it f ex "includes"
- create 2 sub-folders, call them level1 and level2
- now lets create a file, "includes.php"

includes.php
----------------------------------------------

<?
echo "testing";
?>

----------------------------------------------

- now create 3 dummy files, name them dummy.php and distribute
them through each folder, in each dummy.php include "includes.php"

<?
include_once ( 'includes.php' );
?>

<?
include_once ( '../includes.php' );
?>

<?
include_once ( '../../includes.php' );
?>

- now in the dummy.php on the last level, include the dummy.php
from the level below

<?
include_once ( '../../includes.php' );
include_once ( '../dummy.php' );
?>

- now try to run dummy.php from the last level ( the one with 2 includes ), what do you get ? a nice message error stating

Warning: main() [function.include]: Failed opening '' for inclusion (include_path='.;C:\php5\pear') in D:\shared\www\includes\level1\dummy.php on line 2

it's like php processes the first include relative path, goes down the file system tree, stays there and then caches the path, because it doesn't reset to the including script path, it just stays there ...

this is very fustrating when you must/want to include one or more files in every script, and you have several folders and sub-levels.

there are several workarounds, like out them in a common folder, and add it to the include_path either directly in php.ini or using ini_set(), but that would be a real pain in the arse ...

solutions ?

regards,
idss

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to