This is a discussion on PHP 5 function redeclared error within the PHP Language forums, part of the PHP Programming Forums category; .oO(sesser@gmail.com) >>There is nothing wrong with PHP w.r.t require_once. The problem is, in &...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
.oO(sesser@gmail.com)
>>There is nothing wrong with PHP w.r.t require_once. The problem is, in >machine 2: >>.../home -> has a functions.php >>.../home/secure/ -> also has a functions.php > >this proves that the require_once('functions.php') in contents.php is >failing on server 1... No! >there is no functions.php in the 'home' >directory (which is where PHP is looking for the file). PHP looks there first, if it can't find one it looks in /home/secure (the same directory where contents.php is stored). It's all correct. Micha |
|
|||
|
I was trying to simplify things a bit. Unless you change it with a call
to chdir(), the cwd is the same as the script directory. Including a file in a different directory does not change the cwd to that directory. I'm at a loss as to why require_once("functions.php") manages to find secure/functions.php. I think most of us would agree that it's not supposed to happen, unless /home/secure is in the include_path. If it is, then why does require_once() fail to see that it's the same file? Since this happens on Windows, maybe it's a forward slash vs. backward slash misinterpretation within PHP. In any event, providing absolute paths to include/require is the preferred practice. That way you know for certain what you're including. An example: define('SECURE_INCLUDE_ROOT', dirname(__FILE__) . "/secure/"); function require_secure($filename) { require_once(SECURE_INCLUDE_ROOT . $filename); } |
|
|||
|
On 12 Jan 2005 12:59:47 -0800, "chernyshevsky@hotmail.com"
<chernyshevsky@hotmail.com> wrote: >I was trying to simplify things a bit. Unless you change it with a call >to chdir(), the cwd is the same as the script directory. Including a >file in a different directory does not change the cwd to that >directory. Yes, that's the point from the manual snippet I posted. cwd is searched first, then the directory containing the current script. When you include a script outside the cwd, then all include_path directories relative the directory containing the included script become candidates for searching, once all equivalents relative to cwd fail. -- Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool |
|
|||
|
"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:fa5bu018v6rn9v08iiiolm8n7mmugraig5@4ax.com... > On 12 Jan 2005 12:59:47 -0800, "chernyshevsky@hotmail.com" > <chernyshevsky@hotmail.com> wrote: > > >I was trying to simplify things a bit. Unless you change it with a call > >to chdir(), the cwd is the same as the script directory. Including a > >file in a different directory does not change the cwd to that > >directory. > > Yes, that's the point from the manual snippet I posted. cwd is searched first, > then the directory containing the current script. When you include a script > outside the cwd, then all include_path directories relative the directory > containing the included script become candidates for searching, once all > equivalents relative to cwd fail. > > -- > Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk> > <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool Crap. I got egg on my face. I've always understood "current script" as being the file reported by PHP_SELF. Turned out I'm way off. Thank you, Andy and Michael, for point it out. |