note 56511 added to function.include
| From: | Stevenm122084 at aol dot com | Date: | Mon, 05 Sep 2005 22:04:35 +0000 |
| Subject: | note 56511 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94770@lists.php.net to get a copy of this message | ||
I decided to use the include function in one of my functions. It like to drove me crazy! I found two
problems.
1.) Say you want to include a few strings, such as a conf file:
L:\bin\conf\main.conf -
<?php
$classDir = "L:\bin\src\\";
..
..
..
?>
L:\bin\func\using.func -
<?php include 'L:\bin\conf\main.conf';
function using($class)
{
$classFile = $classdir . $class;
include $classFile;
}
Well, this doesn't work. I for awhile It was driving me nuts. I was even talking to the file,
cursing it, telling it that it is stupid. Then for some reason or another I knew that it would work
inside the function too. So, I put the include in the function as well:
L:\bin\func\using.func -
<?php
function using($class)
{
include 'L:\bin\conf\main.conf';
$classFile = $classdir . $class;
include $classFile;
}
And TADA!!! It worked. I just put this on here incase someone does the same stupid thing I did.
on to the next problem, and a stupid one.
2.) Say you want to include a file in the previous directory:
<?php include "../conf/main.conf";
..
..
?>
this doesnt work. For some dumb reason, the makers of PHP want you to include the name of the folder
the php file is in then the '../':
<?php include "func/../conf/main.conf";
..
..
?>
This works. There ya go if you wanted to know.
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56511
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56511&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56511&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56511&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56511&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56511&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56511&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56511&report=yes
Search -- http://master.php.net/manage/user-notes.php