note 97798 added to function.include

From: Date: Sun, 09 May 2010 04:02:51 +0000
Subject: note 97798 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-169083@lists.php.net to get a copy of this message
Problems with including files inside of files included by other files (Tim describes this problem as well) originates from an inconsistency in PHP and how it handles including files. Given a file B that is included in file A, any time you include files in B and the path begins with "../" the path is no longer relative to B it is relative to A. (It sounds silly I know) I tested this in PHP 5.* and it's consistently the problems most people have with this. Note, there isn't a problem when your path does not begin with "../". Now, I have found a trick to fix this problem. And (although no offense to Tim and others who offered great solutions) there is a much more elegant way of making this work. Following my above example, with file A and B to fix the relative pathing simply append "null/../" to the beginning of the include path. "null" is a non-existent directory and Php parses "null/../" as entering some directory then going back up out of it. In the process it allows "../" to follow after the string without any problems. Simply put if your worried about include paths at all make a function: <?php function require_($path) { require_once('null/../' . $path); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 24.57.222.121 ---- Manual Page -- http://www.php.net/manual/en/function.include.php Edit -- https://master.php.net/note/edit/97798 Del: integrated -- https://master.php.net/note/delete/97798/integrated Del: useless -- https://master.php.net/note/delete/97798/useless Del: bad code -- https://master.php.net/note/delete/97798/bad+code Del: spam -- https://master.php.net/note/delete/97798/spam Del: non-english -- https://master.php.net/note/delete/97798/non-english Del: in docs -- https://master.php.net/note/delete/97798/in+docs Del: other reasons-- https://master.php.net/note/delete/97798 Reject -- https://master.php.net/note/reject/97798 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#169083) next »