note 107614 modified in language.constants.predefined by danbrown

From: 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(&#39;__DIR__&#39;) always returns false. Defining __DIR__ will silently fail in PHP 5.3+. This could cause compatibility issues if your script includes other scripts.&#13;&#10;&#13;&#10;Here is proof:&#13;&#10;&#13;&#10;&#60;?php&#13;&#10;echo (defined(&#39;__DIR__&#39;) ? &#39;__DIR__ is defined&#39; : &#39;__DIR__ is NOT defined&#39; . PHP_EOL);&#13;&#10;echo (defined(&#39;__FILE__&#39;) ? &#39;__FILE__ is defined&#39; : &#39;__FILE__ is NOT defined&#39; . PHP_EOL);&#13;&#10;echo (defined(&#39;PHP_VERSION&#39;) ? &#39;PHP_VERSION is defined&#39; : &#39;PHP_VERSION is NOT defined&#39;) . PHP_EOL;&#13;&#10;echo &#39;PHP Version: &#39; . PHP_VERSION . PHP_EOL;&#13;&#10;?&#62;&#13;&#10;&#13;&#10;Output:&#13;&#10;__DIR__ is NOT defined&#13;&#10;__FILE__ is NOT defined&#13;&#10;PHP_VERSION is defined&#13;&#10;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

« previous php.notes (#187818) next »