Re: [PHP4BETA] Is this a good idea for an operator?
| From: | Rasmus Lerdorf | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Re: [PHP4BETA] Is this a good idea for an operator? | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-3065@lists.php.net to get a copy of this message | ||
> Instead of this in PHP/C code
> if ($action=="modify" || $action=="create" || $action=="delete")
> {
>
> have this
>
> if ($action in ("modify","create","delete")) {
>
> Just thought it would be a good idea to throw into the list as I noticed the new operator which
> was to be added to PHP 4.0
> It would definitely be a nice addition to the language.
switch($action) {
case "modify":
case "create":
case "delete":
blah blah;
}
To me this is the cleanest way to do this and it is infinitely flexible in
that you have a built-in negated case by adding a default case, and even
the matching cases can trigger slightly different bits of code. The whole
point of the switch statement is to cleanup up long and complex if
statements just like that.
-Rasmus