> 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



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to