Edit report at https://bugs.php.net/bug.php?id=40296&edit=1
ID: 40296
Comment by: email at philsturgeon dot co dot uk
Reported by: mail at tobyinkster dot co dot uk
Summary: "unless" control structure
Status: Wont fix
Type: Feature/Change Request
Package: *General Issues
Operating System: All
PHP Version: 5.2.0
Block user comment: N
Private report: N
New Comment:
Thanks for stopping by Rasmus, that was a really quick follow up.
I think you might have pointed out the crux of the confusion: being a native
English speaker. To me it makes perfect sense, but I am British.
Unless the condition is true, do this.
I like the post: https://37signals.com/svn/posts/2699-making-sense-with-rubys-
unless
A new keyword just to replace "if ( ! (condition))" might seem like a hassle, and
the objective of the game is not always to make PHP "nice", but it is readable and
logical to many, and is easy to ignore if you don't like it - unless you have
function unless(), but the chances are that function is doing something similar
anyway.
Previous Comments:
------------------------------------------------------------------------
[2012-07-29 20:16:53] rasmus@php.net
Any new keyword breaks BC to some extent because it will break any code that has
an existing unless() function. I agree with others here that unless() can be
quite confusing. A negated conditional keyword lends itself to double negatives.
It also isn't a very common feature in other languages and definitely not
obvious to non-native English speaking people like myself. It is an odd word
that essentially means not-if even though it logically should be equivalent to
"more" as in the opposite of "more" would be "less" and sticking
"un" in front
of it suddenly completely changes the meaning entirely.
------------------------------------------------------------------------
[2012-07-29 20:00:40] email at philsturgeon dot co dot uk
I am surprised to see such a lack of interest on this feature request.
Ruby and Perl both have "unless", and while that is certainly not a reason on its
own, it does show that this is used.
There are two people here saying that unless is confusing. How so? If something
matches false then do whatever. It has an else too, so if something is true it
will be used.
The main point here is not to remove a single !, but to make much cleaner syntax.
if ( ! (isset($foo) or ($foo !== 'bar')) exit('invalid value');
or
unless (isset($foo) and $foo === 'bar') exit('invalid value');
Its a minor difference as I cannot remember a more compelling example, but there
have been numerous times I have wished to reverse this and have unless instead of
an extremely complex if statement.
Unless just makes sense, it's optional, it doesn't break BC, it makes syntax
easier to read in some situations and it is easy to document. If I knew enough C
I'd send in a patch right now as PHP would be better off for having this.
------------------------------------------------------------------------
[2011-12-30 13:50:47] joke at nakhon dot net
I vote against this request. Both perl and ruby's 'unless' confuse me so much. It can
be easy to abuse.
I often encounter someone wrote code like this:
unless a != 7
b = 3
else
b = 6
end
------------------------------------------------------------------------
[2011-08-04 20:59:24] achaia3 at gmail dot com
This would be a convenient feature for sure with no down sides for anybody not wishing to use it.
------------------------------------------------------------------------
[2011-06-05 22:47:45] mattr dot smith at gmail dot com
I also request this feature.
Ruby has this structure too and really adds to the readability of code.
I don't see any argument at against this that is valid other than the fact that
PHP programmers don't want to change.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=40296--
Edit this bug report at https://bugs.php.net/bug.php?id=40296&edit=1