note 117559 deleted from language.constants.predefined by selim61

From: Date: Wed, 01 Jul 2015 14:35:02 +0000
Subject: note 117559 deleted from language.constants.predefined by selim61
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203011@lists.php.net to get a copy of this message
Note Submitter: raat1979 at gmail dot com ---- 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'; } ?>

« previous php.notes (#203011) next »