note 112376 added to language.constants.predefined

From: Date: Sat, 08 Jun 2013 15:08:55 +0000
Subject: note 112376 added to language.constants.predefined
Groups: php.notes 
Request: Send a blank email to php-notes+get-195109@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.199 Probable Submitter: 66.173.231.161 ---- Manual Page -- http://php.net/manual/en/language.constants.predefined.php Edit -- https://master.php.net/note/edit/112376 Del: integrated -- https://master.php.net/note/delete/112376/integrated Del: useless -- https://master.php.net/note/delete/112376/useless Del: bad code -- https://master.php.net/note/delete/112376/bad+code Del: spam -- https://master.php.net/note/delete/112376/spam Del: non-english -- https://master.php.net/note/delete/112376/non-english Del: in docs -- https://master.php.net/note/delete/112376/in+docs Del: other reasons-- https://master.php.net/note/delete/112376 Reject -- https://master.php.net/note/reject/112376 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195109) next »