note 97798 deleted from function.include by danbrown

From: Date: Sun, 09 May 2010 05:20:37 +0000
Subject: note 97798 deleted from function.include by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169084@lists.php.net to get a copy of this message
Note Submitter: rybadour at gmail dot com ---- 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); } ?>

« previous php.notes (#169084) next »