note 72807 added to function.constant
| From: | php-general at lists dot php dot net | Date: | Fri, 02 Feb 2007 04:29:30 +0000 |
| Subject: | note 72807 added to function.constant | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122518@lists.php.net to get a copy of this message | ||
@XC:
That isn't necessary. If a constant is undefined, constant() returns NULL; simply suppressing
the warning should be enough:
<?php
if(defined('FOO') && constant('FOO') === 'bar'){
// ...
}
?>
becomes
<?php
if(@constant('FOO') === 'bar') {
// ...
}
?>
Note that in the first snippet, the call to constant isn't unnecessary as well, and adds a bit
of overhead. If you're set on using the first notation, the following is better:
<?php
if(defined('FOO') && FOO === 'bar') {
// ...
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 12.210.207.241
----
Manual Page -- http://www.php.net/manual/en/function.constant.php
Edit -- https://master.php.net/note/edit/72807
Del: integrated -- https://master.php.net/note/delete/72807/integrated
Del: useless -- https://master.php.net/note/delete/72807/useless
Del: bad code -- https://master.php.net/note/delete/72807/bad+code
Del: spam -- https://master.php.net/note/delete/72807/spam
Del: non-english -- https://master.php.net/note/delete/72807/non-english
Del: in docs -- https://master.php.net/note/delete/72807/in+docs
Del: other reasons-- https://master.php.net/note/delete/72807
Reject -- https://master.php.net/note/reject/72807
Search -- https://master.php.net/manage/user-notes.php