Re: logical AND assignments
| From: | David Harkness | Date: | Wed, 08 Sep 2010 16:38:55 +0000 |
| Subject: | Re: logical AND assignments | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-307889@lists.php.net to get a copy of this message | ||
The reason for "and" to have such a low precedence is so you can use it to
perform conditional processing. You can probably achieve every effect using
"&&", but you'd need more parentheses. More typically you would use
"or" in
this fashion:
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
This checks if DS is defined and defines it if not.
APP_ENV != 'prod' or die('This feature must not be used in production');
If we're in production, stop execution with an error. Using || here would
try to logically or the string 'prod' with the return value of die(). Of
course, die() doesn't return, so the script would exit no matter what
APP_ENV was set to.
David