note 117559 added to language.constants.predefined
| From: | raat1979 at gmail dot com | Date: | Mon, 29 Jun 2015 11:09:39 +0000 |
| Subject: | note 117559 added to language.constants.predefined | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202989@lists.php.net to get a copy of this message | ||
A little update on My previously submitted comment to complement the note by eyecatchup at gmail dot
com.
Magic constants can not be tested with defined($name)
<?php
if(!defined(__DIR__)){
//will not work
}
?>
when for example __DIR__ is not defined and you use it anyway php assumes you meant
'__DIR__' and throws a notice.
because of this assumption we can do:
<?php
if(@__DIR__ == '__DIR__'){
echo 'magic __DIR__ constant NOT defined';
/* insert this code where needed,
remember __DIR__ is a MAGIC constant, it returns the directory name of the file from where __DIR__
is being refered to */
define('__DIR__', dirname(__FILE__));
/* the above define for __DIR__ is completely useless as the MAGIC will be lost,
it will always, no matter where it's called from return the directory name of the file where
__DIR__ the constant was defined. */
}echo{
echo 'magic __DIR__ constant IS defined';
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 89.20.95.34
----
Manual Page -- http://php.net/manual/en/language.constants.predefined.php
Edit -- https://master.php.net/note/edit/117559
Del: integrated -- https://master.php.net/note/delete/117559/integrated
Del: useless -- https://master.php.net/note/delete/117559/useless
Del: bad code -- https://master.php.net/note/delete/117559/bad+code
Del: spam -- https://master.php.net/note/delete/117559/spam
Del: non-english -- https://master.php.net/note/delete/117559/non-english
Del: in docs -- https://master.php.net/note/delete/117559/in+docs
Del: other reasons-- https://master.php.net/note/delete/117559
Reject -- https://master.php.net/note/reject/117559
Search -- https://master.php.net/manage/user-notes.php