note 16750 deleted from function.require by jimw
| From: | jimw@php.net | Date: | Fri, 07 Dec 2001 00:48:11 +0000 |
| Subject: | note 16750 deleted from function.require by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-21744@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...
?>