note 102161 added to function.include
| From: | itsols at gmail dot com | Date: | Mon, 31 Jan 2011 06:28:24 +0000 |
| Subject: | note 102161 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176520@lists.php.net to get a copy of this message | ||
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...
----
Server IP: 69.147.83.197
Probable Submitter: 119.235.2.184
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit -- https://master.php.net/note/edit/102161
Del: integrated -- https://master.php.net/note/delete/102161/integrated
Del: useless -- https://master.php.net/note/delete/102161/useless
Del: bad code -- https://master.php.net/note/delete/102161/bad+code
Del: spam -- https://master.php.net/note/delete/102161/spam
Del: non-english -- https://master.php.net/note/delete/102161/non-english
Del: in docs -- https://master.php.net/note/delete/102161/in+docs
Del: other reasons-- https://master.php.net/note/delete/102161
Reject -- https://master.php.net/note/reject/102161
Search -- https://master.php.net/manage/user-notes.php