Re: __file__ and __line__
| From: | David T-G | Date: | Tue, 15 Oct 2002 03:07:24 +0000 |
| Subject: | Re: __file__ and __line__ | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-119978@lists.php.net to get a copy of this message | ||
Andy --
..and then Ns_Andy said...
%
% what's its use and how to use(Example)?
They're constants that identify where you are. I use __FILE__ so that I
don't have to keep tweaking my code when working in the development
environment:
# this will let us figure out where we are and then always source the right include stuff!
# it does not work with symlinks (__FILE__ reports the *target*)
# you must have a full env tree in your devel tree; we now look exclusively in $DEVELDIR if set
if ( ereg("/home/sites/\.php/",__FILE__) ) # are we *somewhere* in our usual master
tree?
{ $DEVELDIR =
preg_replace("|/.*/home/sites/\.php(.*)/[^/]*$|","$1",__FILE__) ; } # get the
working dir
include("/home/sites/.php$DEVELDIR/includestuff.inc"); # include our various files
Our repository is under /home/sites/.php and there are various
production, development, and test dirs under there. No more hard-coding
/home/sites/.php/test6/includestuff.inc
in the code -- and, worse, forgetting to take it out when promoting
to production! :-) [Yeah, I know that I should assign a variable
containing the "/home/sites/\.php/" string, but it's almost not worth
it in something that has to be self-contained like this and so I haven't
bothered :-]
%
% Thanks
HTH & HAND
% --
% Regards,
:-D
--
David T-G * It's easier to fight for one's principles
(play) davidtg@justpickone.org * than to live up to them. -- fortune cookie
(work) davidtgwork@justpickone.org
http://www.justpickone.org/davidtg/ Shpx gur
Pbzzhavpngvbaf Qrprapl Npg!