note 107614 modified in language.constants.predefined by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 20:37:51 +0000 |
| Subject: | note 107614 modified in language.constants.predefined by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187818@lists.php.net to get a copy of this message | ||
You cannot check if a magic constant is defined. This means there is no point in checking if __DIR__
is defined then defining it.
defined('__DIR__') always returns false.
Defining __DIR__ will silently fail in PHP 5.3+. This could cause compatibility issues if your
script includes other scripts. Here is
proof: <?php echo
(defined('__DIR__') ? '__DIR__ is defined' : '__DIR__ is NOT
defined' . PHP_EOL); echo (defined('__FILE__') ?
'__FILE__ is defined' : '__FILE__ is NOT defined' .
PHP_EOL); echo (defined('PHP_VERSION') ? 'PHP_VERSION is
defined' : 'PHP_VERSION is NOT defined') . PHP_EOL; echo
'PHP Version: ' . PHP_VERSION .
PHP_EOL; ?> Output: __DIR__
is NOT defined __FILE__ is NOT defined PHP_VERSION is
defined PHP Version: 5.3.6
--was--
You cannot check if a magic constant is defined. This means there is no point in checking if __DIR__
is defined then defining it. defined('__DIR__') always returns false.
Defining __DIR__ will silently fail in PHP 5.3+. This could cause compatibility issues if your
script includes other scripts.
Here is proof:
<pre><?php
echo (defined('__DIR__') ? '__DIR__ is defined' : '__DIR__ is NOT
defined' . PHP_EOL);
echo (defined('__FILE__') ? '__FILE__ is defined' : '__FILE__ is NOT
defined' . PHP_EOL);
echo (defined('PHP_VERSION') ? 'PHP_VERSION is defined' : 'PHP_VERSION is
NOT defined') . PHP_EOL;
echo 'PHP Version: ' . PHP_VERSION . PHP_EOL;
?></pre>
Output:
__DIR__ is NOT defined
__FILE__ is NOT defined
PHP_VERSION is defined
PHP Version: 5.3.6
http://php.net/manual/en/language.constants.predefined.php