note 89963 deleted from function.include-once by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 08:04:19 +0000 |
| Subject: | note 89963 deleted from function.include-once by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196792@lists.php.net to get a copy of this message | ||
Note Submitter: nospam at freeproxylist dot org
----
I would like to share one very useful tip with include_* statements. For example we have two classes
first.class.php and second.class.php both located in the same directory (./classes) and first one
uses the second one. So we have:
first.class.php
<?php
include_once './second.class.php';
...
?>
also we have file which uses first.class.php:
<?php
include_once './classes/first.class.php';
...
?>
if you will try to execute your script you will get error. Reason: the current directory is
different and the relative path in first.class.php (./second.class.php) will be incorrect.
Here is two possible solution I have found:
<?php
include_once dirname(__FILE__).'/second.class.php';
...
?>
or
<?php
chdir(dirname(__FILE__));
include_once './second.class.php';
...
?>
Hope that tip will be useful for some other software developer
Admin of http://FreeProxyList.org