This weird behavior is killing

From: Date: Fri, 18 Jun 2004 00:16:04 +0000
Subject: This weird behavior is killing
Groups: php.general 
Request: Send a blank email to php-general+get-188521@lists.php.net to get a copy of this message
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

« previous php.general (#188521) next »