note 113130 deleted from language.constants.predefined by peehaa
| From: | peehaa@php.net | Date: | Mon, 22 May 2017 07:27:13 +0000 |
| Subject: | note 113130 deleted from language.constants.predefined by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-209087@lists.php.net to get a copy of this message | ||
Note Submitter: raat1979 at gmail dot com
----
Magic constants can not be tested with defined($name)
<?php
if(!defined(__DIR__)){
//will not work
}
?>
when __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 that because they are MAGIC constants defining __DIR__
is completely useless
}echo{
echo 'magic __DIR__ constant IS defined';
}
?>