Re: PROPOSAL: 'unless' control structure
| From: | Sara Golemon | Date: | Sun, 12 Jan 2003 19:47:16 +0000 |
| Subject: | Re: PROPOSAL: 'unless' control structure | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-93382@lists.php.net to get a copy of this message | ||
> My apologies if this has been brought up before, but I searched the
> archives and couldn't find a reference to it.
>
> I'm sure this is the sort of thing that would have already been
> implemented if there was any desire for it among the developers, but I
> was wondering if anyone had considered adding support for an "unless"
> control structure, similar to the one Perl has. I personally find it
> much more logical in certain cases. For example, compare this:
>
> [snip]
>
This has been discussed (recently in fact) and won't be done. However,
you *can* give your code the type of readability you're looking for with:
($condition) || {
/* This will only run if $condition evals to false */
}
Or, if you absolutely want that unless() structure in there, you can
create a simple wrapper for it:
unless($condition) || {
/* This will only run if $condition evals to false */
}
function unless($condition) {
return $condition;
}
This makes "unless()" a useless function and wastes clock cycles, but
allows your code to look almost exactly like you're wanting.
You *might* want to type cast $condition to (bool)....
-Pollita