PHP
downloads | documentation | faq | getting help | mailing lists | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Costanti magiche> <Variables From External Sources
Last updated: Fri, 18 Jul 2008

view this page in

Costanti

Indice dei contenuti

Una costante è un identificatore (nome) per un valore. Come si può intuire, tale valore non può cambiare durante l'esecuzione dello script (fanno eccezione le costanti magiche, che, in realtà, non sono costanti). Una costante è "case-sensitive" per default. È convenzione comune che i nomi di costante siano sempre maiuscoli.

In PHP il nome di una costante segue le regole di qualsiasi "etichetta". Un nome di costante valido inizia con una lettera o underscore, seguita da un numero qualsiasi di caratteri alfanumerici o underscore. L'espressione regolare che esprime questa convenzione è: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

Example #1 Nomi di costanti validi ed errati

<?php
// Nomi validi
define("FOO",     "something");
define("FOO2",    "something else");
define("FOO_BAR""something more")
 
// Nomi di costante errati
define("2FOO",    "something");
     
// Nomi validi, ma da evitare:
// un domani potrebbero essere utilizzati dal PHP per fornire costanti magiche
// e quindi si avrebbero problemi nello script
define("__FOO__""something"); 
?>

Nota: In questo contesto una lettera è a-z, A-Z e i caratteri ASCII dal 127 al 255 (0x7f-0xff).

Come le superglobals, costante è sempre globale. Si può accedere alle costanti da qualsiasi punto dello script senza tenere conto della visibilità. Per maggiori dettagli sulla visibilità, leggere la sezione variable scope.

Sintassi

È possibile definire una variabile utilizzando la funzione define(). Una volta definita, a una costante non è possibile cambiare il valore o eliminarla.

Le costanti possono contenere solo dati di tipo scalare (boolean, integer, float e string).

Per ottenere il valore di una costante è sufficiente specificarne il nome. A differenza delle variabili, non è necessario anteporre il simbolo $ al nome di una variabile. Si può anche utilizzare la funzione constant(), per leggere il valore di una costante, nel caso in cui se ne ottenga dinamicamente il nome. Si utilizzi get_defined_constants() per ottenere una lista delle variabili definite.

Nota: Costanti e variabili (globali) si trovano in un "namespace" differente. Questo implica che generalmente TRUE e $TRUE sono differenti.

Se si utilizza il nome di una costante che non è definita, PHP assume che detto valore sia il nome della costante stessa, come se si fosse inserito il testo nel nome . Quando ciò accade PHP segnala il problema con un E_NOTICE. Vedere anche il capitolo del manuale sul perchè $foo[bar] è errata (a meno che prima non definisca bar come costante con define()). Per sapere se una costante è definita, si può utilizzare la funzione defined().

Di seguito sono riportate le principali differenze rispetto le variabili:

  • Le costanti non iniziano con il segno del dollaro ($);
  • Le costanti possono essere definite solo con la funzione define() e non tramite assegnazione;
  • Le costanti possono essere definite e utilizzate ovunque senza seguire le regole di visibilità;
  • Una volta impostate, le costanti non posso essere redefinite e ne annullate;
  • Le costanti possono essere solo valori scalari;

Example #2 Definizione di costanti

<?php
define("COSTANTE", "Ciao mondo.");
echo COSTANTE; // stampa "Ciao mondo."
echo Costante; // stampa "Costante" e genera una notice.
?>



Costanti magiche> <Variables From External Sources
Last updated: Fri, 18 Jul 2008
 
add a note add a note User Contributed Notes
Costanti
Francois Hill
20-Nov-2008 06:41
As a follow-up to Sinured's 19-Jul-2007 09:27 note :

I have also noticed PHP (my version i.e. 5.2.0) allows more characters than specified in constant's names. The slash character ("/") seems to be allowed, notably.

I have used that "feature" to produce uniquely named constants in my different files :

<? php

//This line is copied-pasted in all files, needs not be adpated
define('PATH_FILE_THIS'.__FILE__ ,realpath(dirname(__FILE__)));

//Use constant :
include constant('FPL__PATH_FILE_THIS'.__FILE__).'../etc.';

?>

Had "/" not been a admissible character in a constant's name, hash functions would probably have to have been considered.
seth36 at gmail dot com
13-Jul-2008 08:11
Follow up to last note - After trying this out it seems that ${CFUNC}(); will not work either, however a constant can be used as a reference to a function when used with call_user_func(). The example below is based of ian's original to explain this:

<?php

function A() {
    echo
"<p>I am function A from \$Variable reference</p>\n";

}

function
B() {
    echo
"<p>I am function B from CONSTANT reference</p>\n";

}

$FunctionA = "A";
define("FUNCTIONB", "B");

/*
// #Works - $FunctionA evaluates to "A" and calls corresponding function
// Returns - I am function A from $Variable reference
*/
$FunctionA();

/*
// #Fails - PHP considers FUNCTIONB() a call to user defined "FUNCTIONB", function doesn't exist so PHP throws an error - this IS correct behaviour!
// Returns - Fatal error: Call to undefined function: functionb() in...
*/
FUNCTIONB();

/*
// #Works - $FunctionA variable is passed as string "A" to call_user_func()
// Returns - I am function A from $Variable reference
*/
call_user_func($FunctionA);

/*
// #Works - FUNCTIONB constant is passed as string "B" to call_user_func()
// Returns - I am function B from CONSTANT reference
*/
call_user_func(FUNCTIONB);

?>

Again though why anyone would need / want a constant as a reference to a function escapes me. The function itself has to have the same name as the value of the constant that will refer to it, therefore there's no reason you can't simply call the function normally, infact it's probably better to do so as using a constant for this ensures the following:

1.) A call to define() is required to set the constant
2.) The constant will need it's value determined (as a string) when being passed to call_user_func()
3.) Two functions must be called whenever you call a function in this manner - call_user_func() and the target function.

That's more memory used up in your application, whereas calling the function directly avoids this entirely. My opinion is to forget about constants as function references - use variable functions or call the function directly and keep constants for any fixed parameters you need globally available.
seth36 at gmail dot com
13-Jul-2008 03:12
Reply to ian at willis dot org dot uk

From the second line of the Syntax section above:

"Only scalar data (boolean, integer, float and string) can be contained in constants. Do not define resource constants."

So the 'ccc' value of your constant would be interpreted by php as the string 'ccc', not a reference to the function. Furthermore the cfunc(); call that triggers the error, as far as PHP is concerned, is just a normal function, since constants have no $ prefix, if you used a constant as a reference to a function, how would PHP know what should be handled as a regular function call and what should be handled as a constant function reference as the syntax becomes the same.

You can create a variable from the value of the constant using ${CFUNC} so to create a reference to the function from the constant you might be able to do:

<?php

define
("CFUNC", "ccc");
${
CFUNC}();

?>

I haven't tested this though and in all honesty I can't think why you'd even want to use a constant as a function reference anyway for variable variables it make's sense, particularly when you might not know the function name beforehand. A constant is as it's name implies - it's constant, since it's value doesn't change it has no benefit as a function reference as far as i can see since you must already know the function name (that you set as the value of the constant) in order to create this constant reference, why not just call the function directly?
ian at willis dot org dot uk
16-May-2008 03:25
Another difference - you cannot use a constant to reference a function.

<?php

function ccc()
{
   echo
"CCC\n";
}

function
vvv()
{
   echo
"VVV\n";
}

define('cfunc', 'ccc');
$vfunc = 'vvv';

$vfunc();   // Works
cfunc();    // Fails

?>

Displays:

VVV

Fatal error: Call to undefined function cfunc() in /tmp/test.php on line 17
sgbohu at ~NOSPAM~gmail dot com
22-Apr-2008 04:25
In response to tudor at tudorholton dot com
10-Jul-2007 02:15

The error message does not give incorrect information.

The error indeed is that you did not quote the constant name and PHP tries therefore to use it as a constant.
Since it is not defined, PHP assumes that you meant to quote it and evaluates it as a string.

While this is invalid :
<?php

define
( MY_CONST, 'blah');

?>

This will work :
<?php

define
( 'CONST_NAME', 'MY_CONST' );
define( CONST_NAME, 'blah');

var_dump( CONST_NAME ); // output : string(8) "MY_CONST"
var_dump( MY_CONST ); // output : string(4) "blah"

?>
ben at bendodson dot com
27-Nov-2007 03:14
I recently found I needed a way of retrieving the value of a constant dynamically - e.g. trying to find the value of FOO_BAR by passing 'FOO_' . $someVariableWithValueBAR.  I came up with the following solution:

<?php

define
('FOO_BAR','It works!');
define('FOO_FOO_BAR','It works again!');

// prints 'It works!'
$changing_variable = 'bar';
echo
constant('FOO_' . strtoupper($changing_variable));

// prints 'It works again!'
$changing_variable = 'foo_bar';
echo
constant('FOO_' . strtoupper($changing_variable));

?>

Note the use of strtoupper() as constants should be defined in uppercase for good practice - feel free to remove if you have constants defined in lowercase or you can set $changing_variable as uppercase.

Might be of some use to someone!
Sinured
30-Jul-2007 11:39
Ah, I forgot to point that out in my previous note:

> "Constants may only evaluate to scalar values."

Currently, resources are "abstract datatypes based on integers".
Though this may change in the future, and is_scalar() rejects resources as non-scalar, you can define resource constants, like
<?php define('DB', mysql_connect());?>
(think of STDIN, STDOUT and STDERR).
Resource constants will still remain resources; try var_dump().
Sinured
19-Jul-2007 12:27
> "A valid constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores."

This rules only applies when using constants like <?php echo CONSTANT;?> to not confuse the parser - PHP will be happy with any string for a constant name (define).

<?php
define
('Red herring!', '<°)))><');
#echo Red herring!;
// The above example will not work, the parser will get
// angry seeing a whitespace where it shouldn’t be.

// Let’s have that with constant():
echo constant('Red herring!'); // <°)))><
?>

You could go on with newlines, tabs and stuff... that is, however, crude coding style.
tudor at tudorholton dot com
09-Jul-2007 05:15
Note that constant name must always be quoted when defined.

e.g.
define('MY_CONST','blah') - correct
define(MY_CONST,'blah') - incorrect

The following error message also indicates this fact:
Notice:  Use of undefined constant MY_CONST - assumed 'MY_CONST' in included_script.php on line 5

Note the error message gives you some incorrect information.   'MY_CONST' (with quotes) doesn't actually exist anywhere in your code.  The error _is_ that you didn't quote the constant when you defined it in the 'assumed' file.
Andreas R.
30-Apr-2007 07:19
If you are looking for predefined constants like
* PHP_OS (to show the operating system, PHP was compiled for; php_uname('s') might be more suitable),
* DIRECTORY_SEPARATOR ("\\" on Win, '/' Linux,...)
* PATH_SEPARATOR (';' on Win, ':' on Linux,...)
they are buried in 'Predefined Constants' under 'List of Reserved Words' in the appendix:
http://www.php.net/manual/en/reserved.constants.php
while the latter two are also mentioned in 'Directory Functions'
http://www.php.net/manual/en/ref.dir.php
pdenny at magmic dot com
18-Feb-2007 09:46
Note that constants can also be used as default argument values
so the following code:

  define('TEST_CONSTANT','Works!');
  function testThis($var=TEST_CONSTANT) {
      echo "Passing constants as default values $var";
  }
  testThis();

will produce :

Passing constants as default values Works!

(I tried this in both PHP 4 and 5)
dexen at google dot me dot up
05-Sep-2006 04:02
1) Constants are invaluable when you want to be sure that *nobody*  changes your important piece of data through lifetime of script -- especially when you're developing in team -- as this can cause strange, hard to track bugs.

2) Using constants is prefered over ``magic values'', as it leads to self-documenting code. Also saves you from scanning and tweaking tens of files should the value ever change.
Consider example: <?php
if ( $headers['code'] = 505 ) { //wth is 505? What do following code do? ?>
versus: <?php
if ( $headers['code'] = HTTP_VERSION_NOT_SUPPORTED ) {
  
$this->useHttp = '1.0'; ?>

In response to ``kencomer'':
3) Why not to use <?php
define
( 'DEBUG', FALSE );
define( 'DEBUG', TRUE ); ?>
and comment one of them out as needed when developing/deploying?
That'd save a lot of ugly ``if ( defined( 'DEBUG' ) && DEBUG ) {}''.

4) For debugging toggled on/off you pretty often want to use assert() anyway. You're free to turn it on/off at any moment (thou you better do it only once ;) ). assert() gives some nice details upon failed assertion, like file/line/function and context (that's invaluable!)
martin at larsen dot dk
23-Feb-2006 02:24
I find variables much more flexible than constants because variables can be used inside quotes and heredocs etc. Especially for language systems, this is nice.

As stated in one of the previous notes, there is no speed penalty by using variables. However, one issue is that you risc name collision with existing variables. When implementing a language system I simply found that adding a prefix to all the variables was the way to go, for example:

$LNG_myvar1 = "my value";

That is easier and performs faster than using arrays like

$LNG['myvar'] = "my value";

As a final note, implementing a new superglobal in PHP would make using constants much more beneficial. Then it could be used in qoutes like this:

"The constant myconst has the value $CONSTANTS[myconst] !"
anj at aps dot anl dot gov
20-Dec-2005 08:42
It is possible to define constants that have the same name as a built-in PHP keyword, although subsequent attempts to actually use these constants will cause a parse error. For example in PHP 5.1.1, this code

    <?php
    define
("PUBLIC", "Hello, world!");
    echo PUBLIC;
   
?>

gives the error

    Parse error: syntax error, unexpected T_PUBLIC in test.php on line 3

This is a problem to be aware of when converting PHP4 applications to PHP5, since that release introduced several new keywords that used to be legal names for constants.
kencomer at NOSPAM dot kencomer dot com
14-Sep-2005 05:38
Being a belt and suspenders person, when I use a constant to do flow control (i.e., using constants to determine which version of a section of the program should be used), I always use something like:

if ( defined('DEBUG') && TRUE===DEBUG )

If you accidentally use DEBUG somewhere before it is defined, PHP will create a new constant called DEBUG with the value 'DEBUG'. Adding the second comparison will prevent the expression from being TRUE when you did not intentionally create the constant. For the constant DEBUG, this would rarely be a problem, but if you had (e.g.) a constant used to determine whether a function was created using case-sensitive comparisons, an accidental creation of the constant IGNORE_CASE having the value 'IGNORE_CASE' could drive you up the wall trying to find out what went wrong, particularly if you had warnings turned off.

In almost all code I write, I put this function definition in my configuration section:

if (!function_exists("debug_print")) {
  if ( defined('DEBUG') && TRUE===DEBUG ) {
    function debug_print($string,$flag=NULL) {
      /* if second argument is absent or TRUE, print */
      if ( !(FALSE===$flag) )
        print 'DEBUG: '.$string . "\n";
    }
  } else {
    function debug_print($string,$flag=NULL) {
    }
  }
}

Then, in my code, I'll sprinkle liberal doses of debug code like :

define("DEBUG_TRACK_EXAMPLE_CREATION",FALSE);
class Example extends Something {
  __construct($whatever) {
    debug_print( "new instance of Example created with '$whatever'\n",DEBUG_TRACK_EXAMPLE_CREATION);
  }
}

and :

debug_print("finished init.\n")

In the first case, I would not want to see that message every time I went into DEBUG mode, so I made it a special case. The second case is always printed in DEBUG mode. If I decide to turn everything on, special cases and all, all I have to do is comment out the "if" line in debug_print() and presto magicko! It costs a little and gains a lot.

As another belt-and-suspenders aside, notice that, unlike most people, I put the language constant (e.g.,TRUE, "string", etc.) on the left side of the comparison. By doing that, you can never accidentally do something like
  if ( $hard_to_find_error="here" )

because you always write it as
  if ( "here"==$no_error )

or, if you got it wrong,
  if ( "here"=$easy_to_find_parse_error )
a dot eibach at gmx dot net
01-Sep-2005 02:11
It took me almost 30 minutes to find out what was wrong in my code. I thought I had defined all constants correctly: correct quotes, and whatnot.
The problem: I am a C programmer and I used #define with the preprocessor hash sign! No effect, naturally.
So if you happen to come from C world and you program PHP, *DO NOT* use the preprocessor hash as you're used to in C.
Angelina Bell
25-Jul-2005 12:39
It is so easy to create a constant that the php novice might do so accidently while attempting to call a function with no arguments.  For example:
<?php
function LogoutUser(){
// destroy the session, the cookie, and the session ID
 
blah blah blah;
  return
true;
}
function
SessionCheck(){
 
blah blah blah;
// check for session timeout
...
    if (
$timeout) LogoutUser// should be LogoutUser();
}
?>

OOPS!  I don't notice my typo, the SessionCheck function
doesn't work, and it takes me all afternoon to figure out why not!

<?php
LogoutUser
;
print
"new constant LogoutUser is " . LogoutUser;
?>
ck
27-May-2005 07:23
Re: Storm.
I ran that code (in PHP4)
<?php
if (DEBUG) {
  
// echo some sensitive data.
}
?>
and saw this warning:
"Use of undefined constant DEBUG - assumed 'DEBUG'"

A clearer workaround is to use
<?php
if (defined('DEBUG')) {
  
// echo some sensitive data.
}
?>
Thanks for pointing out this big gotcha.

Another reason to turn on warnings during testing.  Good web servers are set up to suppress warning and error output to the browser, so this is handy:
<?php
if (defined('DEBUG')) {
 
error_reporting(E_ALL);
 
set_error_handler('debug_ErrorHandler');
}
function
debug_ErrorHandler($errno, $errstr, $errfile, $errline) {
  print(
"PHP Error [$errno] [$errstr] at $errline in $errfile.<br>");
}
?>
hafenator2000 at yahoo dot com
21-Apr-2005 02:09
PHP Modules also define constants.  Make sure to avoid constant name collisions.  There are two ways to do this that I can think of.
First: in your code make sure that the constant name is not already used.  ex. <?php if (! defined("CONSTANT_NAME")) { Define("CONSTANT_NAME","Some Value"); } ?>  This can get messy when you start thinking about collision handling, and the implications of this.
Second: Use some off prepend to all your constant names without exception  ex. <?php Define("SITE_CONSTANT_NAME","Some Value"); ?>

Perhaps the developers or documentation maintainers could recommend a good prepend and ask module writers to avoid that prepend in modules.
storm
18-Apr-2005 09:54
An undefined constant evaluates as true when not used correctly. Say for example you had something like this:

settings.php
<?php
// Debug mode
define('DEBUG',false);
?>

test.php
<?php
include('settings.php');

if (
DEBUG) {
  
// echo some sensitive data.
}
?>

If for some reason settings.php doesn't get included and the DEBUG constant is not set, PHP will STILL print the sensitive data. The solution is to evaluate it. Like so:

settings.php
<?php
// Debug mode
define('DEBUG',0);
?>

test.php
<?php
include('settings.php');

if (
DEBUG == 1) {
  
// echo some sensitive data.
}
?>

Now it works correctly.
Charles
12-Jan-2005 01:50
To clarify from the previous post:

When you define a constant, it becomes fixed at that point and is immutable. You can add variables - but the constant becomes the contents of that variable when the define is evaluated. If you try:

define( "_A_TEXT" , "The value is " . $arr[$i] );

It would be evaluated ONCE with the current value of the $i index of array $arr. As the post pointed out, this is probably not what you want. You can easily create:

define( "_A_TEXT" , "The value is ");
....
echo _A_TEXT . $arr[$i];

Which would give you what you wanted: the constant string with the contents of the array appended.
the_coder at colina2004 dot com
24-Jun-2004 01:42
I'm currently working on a site that has got to have two languages, and I wanted to use define's in functions to make everything simpler.

However, I ran into a problem. PHP doesn't recognize the variable in:
define("constantName", "This is an array variable - {$array[$i][2]}");

I can't use that in a for cycle, like I wanted to:

for ($i = 0; $i < count($array); $i++) {
echo constantName . "<br />"
}

The method I found (I think it's been mentioned before) is to:

define("constantName", "This is an array variable - %s");

And then:

for ($i = 0; $i < count($array); $i++) {
printf(constantName, $array[$i][2]);
}
kumar at farmdev
25-Oct-2003 05:59
before embarking on creating a language system I wanted to see if there was any speed advantage to defining language strings as constants vs. variables or array items.  It is more logical to define language strings as constants but you have more flexibility using variables or arrays in your code (i.e. they can be accessed directly, concatenated, used in quotes, used in heredocs whereas constants can only be accessed directly or concatenated).

Results of the test:
declaring as $Variable is fastest
declaring with define() is second fastest
declaring as $Array['Item'] is slowest

=======================================
the test was done using PHP 4.3.2, Apache 1.3.27, and the ab (apache bench) tool.
100 requests (1 concurrent) were sent to one php file that includes 15 php files each containing 100 unique declarations of a language string.

Example of each declaration ("Variable" numbered 1 - 1500):
<?php
$GLOBALS
['Variable1'] = "A whole lot of text for this variable as if it were a language string containing a whole lot of text";
?>
<?php
define
('Variable1' , "A whole lot of text for this variable as if it were a language string containing a whole lot of text");
?>
<?php
$GLOBALS
['CP_Lang']['Variable1'] = "A whole lot of text for this variable as if it were a language string containing a whole lot of text";
?>

Here are the exact averages of each ab run of 100 requests (averages based on 6 runs):
variable (24.956 secs)
constant (25.426 secs)
array (28.141)

(not huge differences but good to know that using variables won't take a huge performance hit)
ewspencer at industrex dot com
18-Aug-2003 06:30
I find using the concatenation operator helps disambiguate value assignments with constants. For example, setting constants in a global configuration file:

define('LOCATOR',   "/locator");
define('CLASSES',   LOCATOR."/code/classes");
define('FUNCTIONS', LOCATOR."/code/functions");
define('USERDIR',   LOCATOR."/user");

Later, I can use the same convention when invoking a constant's value for static constructs such as require() calls:

require_once(FUNCTIONS."/database.fnc");
require_once(FUNCTIONS."/randchar.fnc");

as well as dynamic constructs, typical of value assignment to variables:

$userid  = randchar(8,'anc','u');
$usermap = USERDIR."/".$userid.".png";

The above convention works for me, and helps produce self-documenting code.

-- Erich
php-comment-2003-july-24 at ryandesign dot de
24-Jul-2003 07:04
Late reply to fmmarzoa at gmx dot net: You're better off using sprintf format and defining your strings like this:

define('strArticleDescr', 'Published by %1$s on %2$s in %2$s');

It's more standard than what you're doing. Then instead of outputting it using an eval, do this:

echo sprintf(strArticleDescr, $article_author, $article_date, $article_lang_name');

And even better for i18n and l10n, don't use defines; use gettext. See the PHP manual section on gettext and the GNU gettext website. Gettext requires some modification of the way you think about strings but I find it worthwhile to make that adjustment.
Mike Powell
24-Mar-2003 08:46
In response to the notes above about variable references in constants, double quotes isn't a proper solution because it parses the variable at the time the constant is defined. The desired behavior is to have the variables parsed at the time the constant is referenced, and this behavior can really only be achieved by using eval(), as described above.
gv (at) damnsw (dot) net
05-Nov-2002 08:08
fmmarzoa: In PHP 4.2.2/CLI, I had no problem setting define()'s to the contents of variables:

<?
    $foo
= "PHP";
   
define( "bar", "$foo is a good thing." );
    print
bar;
?>

Will print "PHP is a good thing.".

A notable difference, however, between my example and yours is your use of single-quotes.  Strings in single quotes (') will not be expanded:

print '$foo';

Will print '$foo', not the contents of $foo.

http://www.php.net/manual/en/language.types.string.php

--gv
alan at akbkhome dot com
23-Mar-2002 09:08
The __FILE__ constant in 4.2rc1 (CLI) will return the location of script specified to be run, rather than the absolute file.

eg. /usr/bin/phpmole (a softlink to /usr/lib/php/phpmole/phpmole.php)

started like this
bash#/usr/bin/phpmole
 
the line echo __FILE__ in phpmole.php will output /usr/bin/phpmole - in the CGI it would have returned /usr/lib/php/phpmole/phpmole.php

the workaround is to check for links!!
$f = __FILE__;
if (is_link($f)) $f = readlink($f);
katana at katana-inc dot com
25-Feb-2002 11:53
Warning, constants used within the heredoc syntax (http://www.php.net/manual/en/language.types.string.php) are not interpreted!

Editor's Note: This is true. PHP has no way of recognizing the constant from any other string of characters within the heredoc block.
afuse at yahoo dot com
10-Jun-2001 10:42
The pre-defined constant '__FILE__' does not work in same way at every version of PHP.

Some version of PHP has the relative path, and some other has the absolute path on __FILE__ constant..

Please be carefull in use..

[PS]
I have not tested at all versions of PHP but the version of 4.04pl.. and 4.05 are certainly not working in same way..  If you want to see that bug(?), I can show you an example.
silvein at sonique dot com
23-Jan-2001 05:54
It may be useful to note that, in php4 (what version this started I don't know, but it didn't do it before we upgraded to php4) __FILE__ will follow symlinks to the origional file.
tom dot harris at home dot com
04-Aug-2000 05:44
To get a full path (the equivalent of something like "__PATH__") use
dirname($SCRIPT_FILENAME)
to get the directory name of the called script and
dirname(__FILE__)
to get the directory name of the include file.

Costanti magiche> <Variables From External Sources
Last updated: Fri, 18 Jul 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites