note 102161 deleted from function.include by danbrown
| From: | danbrown@php.net | Date: | Mon, 31 Jan 2011 13:43:39 +0000 |
| Subject: | note 102161 deleted from function.include by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176529@lists.php.net to get a copy of this message | ||
Note Submitter: itsols at gmail dot com
----
When making multiple includes (i.e., including a file from one location,and that file includes
another). Here's an example.
Assume your paths are like this:
File1: www/MyProject/main.php
<?php
include "../FirstInclude.php"; // "FirstInclude.php" in in the parent folder
echo "Answer=$A";
?>
File2: www/FirsInclude.php
<?php
include "/Info/Variables.php";
$A=$B;
?>
File3: www/Info/Variables.php
<?php
$B=5;
?>
The problem: On running main.php from within www/MyProject, this is what happens:
1. main.php successfully includes the PARENT file FirstInclude.php.
2. FirstInclude.php, looks for Variables.php INSIDE Info, and it EXPECTS Info to be inside
MyProject.php since that's where the main.php runs.
3. Rather it fails to find it since Variables.php is in www/Info.
4. So inside www/FirstInclude.php, the variable $B is set to nothing.
5. Thus $A is nothing.
6. So the output is "Answer=".
Note: In order to correctly include the Variables.php file, you should write the include line at
like this:
<?php
include "/Info/Variables.php"; //note the use of PARENT reference since it is actually
running inside www/MyProject
?>
Hope this helps...