note 112376 deleted from language.constants.predefined by googleguy

From: Date: Sat, 08 Jun 2013 16:10:50 +0000
Subject: note 112376 deleted from language.constants.predefined by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-195110@lists.php.net to get a copy of this message
Note Submitter: cHao ---- Although its *value* might change from statement to statement or file to file, a magic constant's *existence* is not dependent on configuration, extensions, or even where the constant is used. It's entirely based on what version of PHP you're using. That means if you want to know whether a magic constant exists and is really magic, you would normally just check the PHP version. If for some reason you only want to test for the constant's existence (for example, to hack in a value for __DIR__ iff there isn't one already), you can do so by comparing the constant to its name. In PHP, undefined constants are equal to a stringification of their names, so for example __DIR__ would initially be equal to "__DIR__" in PHP <5.3. Since you'd have to resort to trickery and really bad naming conventions at the same time to have things whose names look like their respective constants, the test is reliable until you actually fudge a value for the constant. Note, though: PHP will spit out notices when you make it use undefined constants. You can silence the notice with @, and this is one of those occasions where it makes sense to do so.

« previous php.notes (#195110) next »