note 32574 added to function.include
| From: | pages at inrp dot fr | Date: | Sun, 01 Jun 2003 02:25:58 +0000 |
| Subject: | note 32574 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-49509@lists.php.net to get a copy of this message | ||
As mentionned above by Ivo, it's important to note
that when you do nested includes like in:
myapp/index.php
---------------
<?php
include "../smart_functions/main.inc.php";
?>
a_lot_of_smart_functions/main.inc.php
-------------------------------------
<?php
include "functions_for_this.php";
include "functions_for_that.php";
etc ...
?>
PHP will search the file "functions_for_this.php"
- first in the "myapp/" directory
- and only if it doesn't find it in the "myapp/"
directory it will search in the "a_lot_of_smart_functions/"
This is in fact a quite annoying "feature" :-(
Because if I have a file called "functions_for_this.php" in
the "myapp/" directory, then I won't see the functions defined
in the file "a_lot_of_smart_functions/functions_for_this.php"
anymore. In the worst case, the presence of some files in
MY application directory can break a library of functions
defined in ANOTHER directory!
PS: I know I can replace
include "functions_for_this.php";
by
include dirname(__FILE__)."/functions_for_this.php";
in "a_lot_of_smart_functions/main.inc.php" but:
a. it'ugly,
b. the __FILE__ pseudo-constant is undocumented,
c. __FILE__ does not work in the same way with
every version of PHP.
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32574
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32574&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32574&report=yes