note 89963 added to function.include-once

From: Date: Tue, 31 Mar 2009 04:51:58 +0000
Subject: note 89963 added to function.include-once
Groups: php.notes 
Request: Send a blank email to php-notes+get-152641@lists.php.net to get a copy of this message
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 ---- Server IP: 212.24.129.51 Probable Submitter: 90.178.216.222 ---- Manual Page -- http://www.php.net/manual/en/function.include-once.php Edit -- https://master.php.net/note/edit/89963 Del: integrated -- https://master.php.net/note/delete/89963/integrated Del: useless -- https://master.php.net/note/delete/89963/useless Del: bad code -- https://master.php.net/note/delete/89963/bad+code Del: spam -- https://master.php.net/note/delete/89963/spam Del: non-english -- https://master.php.net/note/delete/89963/non-english Del: in docs -- https://master.php.net/note/delete/89963/in+docs Del: other reasons-- https://master.php.net/note/delete/89963 Reject -- https://master.php.net/note/reject/89963 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152641) next »