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
2012/4/10 Nikita Popov nikita.ppv@googlemail.com
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?
I think this is a useful simplification of the language, removing an
unnecessary exception. Would it also make sense to make empty() into a
library function instead of a language construct? That would not result in
any BC break as far as I can see, but would allow some things that are
currently impossible (e.g., a method called "empty") and further simplify
the language.
Nikita
PS: The patch is trivial: https://gist.github.com/2355274
On Tue, Apr 10, 2012 at 4:12 PM, Jelle Zijlstra jelle.zijlstra@gmail.comwrote:
2012/4/10 Nikita Popov nikita.ppv@googlemail.com
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?
I think this is a useful simplification of the language, removing an
unnecessary exception. Would it also make sense to make empty() into a
library function instead of a language construct? That would not result in
any BC break as far as I can see, but would allow some things that are
currently impossible (e.g., a method called "empty") and further simplify
the language.Nikita
PS: The patch is trivial: https://gist.github.com/2355274
--
+1 on this. Could you draft this into an RFC for us?
--Kris
I think this is a useful simplification of the language, removing an
unnecessary exception. Would it also make sense to make empty() into a
library function instead of a language construct? That would not
result in
any BC break as far as I can see, but would allow some things that are
currently impossible (e.g., a method called "empty") and further
simplify
the language.
It would, as an empty function would spit notices if the variable
doesn't exist (or would have to use references, which would create the
variable if it didn't exist already) and therefore destroy the primary
use of that construct ... oh and such an empty won't be different from a
simple "if" or bool cast.
johannes
2012/4/10 Johannes Schlüter johannes@schlueters.de
I think this is a useful simplification of the language, removing an
unnecessary exception. Would it also make sense to make empty() into a
library function instead of a language construct? That would not
result in
any BC break as far as I can see, but would allow some things that are
currently impossible (e.g., a method called "empty") and further
simplify
the language.It would, as an empty function would spit notices if the variable
doesn't exist (or would have to use references, which would create the
variable if it didn't exist already) and therefore destroy the primary
use of that construct ... oh and such an empty won't be different from a
simple "if" or bool cast.johannes
You are quite right; I'm sorry for forgetting about that.
Hi!
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()).
Don't see any problem with that, looks good. Please add some tests
(including function calls and some expressions) and make a pull request.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
On Tue, Apr 10, 2012 at 4:51 PM, Stas Malyshev smalyshev@sugarcrm.comwrote:
Hi!
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()).Don't see any problem with that, looks good. Please add some tests
(including function calls and some expressions) and make a pull request.Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227--
Err isn't this something that should go through the RFC process first? I
think it's a good idea and I'll probably vote for it, but as I understand
the RFC process was created specifically for stuff like this.
--Kris
Hi!
Err isn't this something that should go through the RFC process first?
I think it's a good idea and I'll probably vote for it, but as I
understand the RFC process was created specifically for stuff like this.
One doesn't preclude the other. Pull is code, RFC is discussion, they
can go in parallel.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
On Tue, Apr 10, 2012 at 5:46 PM, Stas Malyshev smalyshev@sugarcrm.comwrote:
Hi!
Err isn't this something that should go through the RFC process first?
I think it's a good idea and I'll probably vote for it, but as I
understand the RFC process was created specifically for stuff like this.One doesn't preclude the other. Pull is code, RFC is discussion, they
can go in parallel.Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Well, technically it's discussion and vote. I know we've been wanting to
get out of the habit of "push first, ask later," which is precisely what
RFC helps us avoid. Personally, I think any commits for a non-minor change
(i.e. a new feature) should be branched and left unmerged until it passes
through the RFC voting process. I'm a big fan of consistency over ad hoc
processes. ;)
--Kris
Hi!
Well, technically it's discussion /and/ vote. I know we've been wanting
to get out of the habit of "push first, ask later," which is precisely
what RFC helps us avoid. Personally, I think any commits for a
Nobody's pushing anything. We're talking about implementing it in a
fork, it's completely different thing.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
On Tue, Apr 10, 2012 at 10:12 PM, Stas Malyshev smalyshev@sugarcrm.comwrote:
Hi!
Well, technically it's discussion /and/ vote. I know we've been wanting
to get out of the habit of "push first, ask later," which is precisely
what RFC helps us avoid. Personally, I think any commits for aNobody's pushing anything. We're talking about implementing it in a
fork, it's completely different thing.Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
I must've missed that part. Who was it that said this would be a separate
forked project? If so, then yeah obviously it's not up to us one way or
another. And if he's just committing changes locally and/or pushing to an
unmerged branch, then there's no harm because it's not actually touching
the trunk. What I'm saying is that, before such changes are merged into
the actual PHP 5.4 branch, the idea needs to be voted on through the RFC
process.
Besides, it's a better idea to wait anyway because the simple act of
drafting the RFC helps the author to clarify exactly what s/he wants to do
before jumping into the code. Furthermore, subsequent input from users may
change the direction, forcing the author to rewrite code, which wastes
time. And if the proposal is rejected, that person would've written all
that code for nothing.
So either way you look at it, it seems to me at least that drafting the RFC
is the logical first step.
--Kris
hi Kris,
I must've missed that part. Who was it that said this would be a separate
forked project? If so, then yeah obviously it's not up to us one way or
another. And if he's just committing changes locally and/or pushing to an
unmerged branch, then there's no harm because it's not actually touching
the trunk. What I'm saying is that, before such changes are merged into
the actual PHP 5.4 branch, the idea needs to be voted on through the RFC
process.
All that was asked here is to provide a pull request and a RFC so we
can evaluate this change. Nobody ever mentioned that this change will
be merged into any of our stable branches. Everything's fine and is
done as it should be.
Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
hi Kris,
I must've missed that part. Who was it that said this would be a
separate
forked project? If so, then yeah obviously it's not up to us one way or
another. And if he's just committing changes locally and/or pushing to
an
unmerged branch, then there's no harm because it's not actually touching
the trunk. What I'm saying is that, before such changes are merged into
the actual PHP 5.4 branch, the idea needs to be voted on through the RFC
process.All that was asked here is to provide a pull request and a RFC so we
can evaluate this change. Nobody ever mentioned that this change will
be merged into any of our stable branches. Everything's fine and is
done as it should be.Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Alrighty. So long as we're not merging any new features or behavioral
changes into the stable branches without an RFC, I'm happy. =)
--Kris
Sent from my iPad
在 2012-4-11,6:54,Nikita Popov nikita.ppv@googlemail.com 写道:
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.
+1 for this, but what about is set? They shou be consistent, :)
Thanks
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
Currently the empty() language construct only works on variables. You
can write if (empty($array)) but not empty if (empty(getSomeArray()).
I've mentioned this thought off-list already but let's discuss it
officially:
A fear I have is that this makes empty more looking like a function,
while not being one. Right now one notices quite quickly that it is
something else. Things like $check = $condition ? "empty" : "isset";
$check($bar); trigger an even more confusing error (Call to undefined
function)
I'm not sure whether that's a strong argument, but I guess it's good
enough to be noted :-)
johannes
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?!
On the line number indicated in the message :-)
More seriously, if the guts of PHP can easily detect when you are not
really write context versus this, just fix the error message to
something more meaningful.
--
brain cancer update:
http://richardlynch.blogspot.com/search/label/brain%20tumor
Donate:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE