atom feed22 messages in net.php.lists.internals[PHP-DEV] Allow non-variable argument...
FromSent OnAttachments
Nikita PopovApr 10, 2012 3:53 pm 
Jelle ZijlstraApr 10, 2012 4:12 pm 
Kris CraigApr 10, 2012 4:14 pm 
Johannes SchlüterApr 10, 2012 4:31 pm 
Jelle ZijlstraApr 10, 2012 4:37 pm 
Stas MalyshevApr 10, 2012 4:50 pm 
Kris CraigApr 10, 2012 5:08 pm 
Xinchen HuiApr 10, 2012 5:25 pm 
Stas MalyshevApr 10, 2012 5:46 pm 
Kris CraigApr 10, 2012 6:27 pm 
Stas MalyshevApr 10, 2012 10:11 pm 
Kris CraigApr 10, 2012 10:26 pm 
Pierre JoyeApr 10, 2012 10:30 pm 
Kris CraigApr 10, 2012 10:37 pm 
Johannes SchlüterApr 12, 2012 4:05 pm 
Pal KonyvesApr 13, 2012 2:36 am 
Nikita PopovApr 13, 2012 6:00 am 
Etienne KneussApr 13, 2012 6:37 am 
Pal KonyvesApr 13, 2012 7:21 am 
Etienne KneussApr 13, 2012 9:12 am 
Richard LynchMay 5, 2012 8:47 am 
Richard LynchMay 5, 2012 8:48 am 
Subject:[PHP-DEV] Allow non-variable arguments to empty()
From:Nikita Popov (niki@googlemail.com)
Date:Apr 10, 2012 3:53:15 pm
List:net.php.lists.internals

Hey internals!

Currently the empty() language construct only works on variables. You can write if (empty($array)) but not empty if (empty(getSomeArray()).

The original reason for this restriction probably is that - in a way - it "doesn't make sense" to pass anything but a variable to empty() as you could just use the ! operator in this case. if (empty(getSomeArray())) is logically equivalent to if (!getSomeArray()).

I'd like to propose to change empty() to accept arbitrary expressions.

The reason is simple: Even though it is possible to write if (!getSomeArray()) with the same effect, if (empty(getSomeArray())) reads much nicer. !getSomeArray() to me somehow implies that getSomeArray() may return a bool(false) or something like that. On the other hand empty(getSomeArray()) seems naturally fit for checking for empty arrays.

Another reason is that currently you get a very obscure error message if you try to use empty() on a function return value: "Can't use function return value in write context". Aha. Where did I try to write to the return value?!

So, what do you think?

Nikita

PS: The patch is trivial: https://gist.github.com/2355274