note 16750 added to function.require
| From: | fangyidong at 263 dot net | Date: | Mon, 12 Nov 2001 10:17:37 +0000 |
| Subject: | note 16750 added to function.require | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-20748@lists.php.net to get a copy of this message | ||
To my surprise,require is quite different to #include in C.For example,I install my web applications
in a subdirectory "hglaser" of $DOCUMENT_ROOT,and directory "hglaser" contains 2
subdirectories:"inc" and "test".I place a file "lib.inc.php" in
directory "inc",the following is the content of this file:
lib.inc.php
===========
<?
require("classes.inc.php");
?>
The file "classes.inc.php" contains the definition of classes.And then,I place a file
"test.php" in the diretory "test":
test.php
========
<?
require("../lib/lib.inc.php");
?>
The PHP told me that the lib.inc.php can not open the file "classes.inc.php",which will
never happen in C!
I can not accept this,so I begin to find out a way to resolve this problem:
I wrote a function named "require_me" in file "require_me.inc.php" in diretory
"lib":
require_me.inc.php
==================
<?
function require_me($relative_path){
$install_subdir="hglaser";//subdirectory where the web application installed
if($install_subdir==""){
require($GLOBALS["DOCUMENT_ROOT"].$relative_path);
}
else{
require($GLOBALS["DOCUMENT_ROOT"]."/".$install_subdir.$relative_path);
}
}
?>
Now modify the file "lib.inc.php" and "test.php":
lib.inc.php
===========
<?
require_me("/inc/lib/lib.inc.php");
?>
test.php
========
<?
require("../inc/lib/require_me.inc.php");
require_me("/inc/lib/lib.inc.php");
//require_me...
?>
--
http://www.php.net/manual/en/function.require.php
http://master.php.net/manage/user-notes.php?action=edit+16750
http://master.php.net/manage/user-notes.php?action=delete+16750
http://master.php.net/manage/user-notes.php?action=reject+16750