Hello PHP Internals!
I'd like to put the variadic empty() RFC to vote.
RFC: https://wiki.php.net/rfc/variadic_empty
Voting will finish in 14 days time on March 21st.
Thanks,
Tom
Hey PHP Internals,
So there hasn't been much discussion on this RFC, and yet a lot of people have
voted -1 on it. This is a little disappointing because I'm not entirely sure why
people are against it - and no one seems to want to debate it either.
From pre-RFC discussions, two main concerns were raised:
- This will promote the creation of poor code.
- The proposed semantics of empty() is wrong. It should be equivalent to logically
AND'ing empty()'s arguments together - just like with isset().
To readdress these two points:
Any feature that reduces the amount of written code can be said to make it
easier to write code - regardless of whether this is good or bad code. That
part is up to the developer.
Perhaps the examples in my RFC do not portray this feature in the best of
lights - they were simply meant to show the more extreme usages of empty()
in popular, real-world codebases. So let me provide some statistics.
I ran the following egrep on a number of CMSs (the regular expression used isn't
perfect, but it still gives some sort of approximation):
egrep -rio '(empty(.*) (|| empty(.))+)|(!empty(.) *(&& !empty(.))+)' project_dir/ | wc -l
Results:
WordPress: 50
OpenCart: 22
phpbb: 36
Drupal: 74
SMF2.1: 266
Joomla: 23
So the proposed short-hand notation of empty() in this RFC does have its
usages. Just as a full disclaimer though, framework codebases will not see
this same usefulness since they don't handle business-specific validation logic
on input fields, web service data, etc (which seems like the predominant usage
of multiple empty()'s in a single condition).
The falsy semantics of empty() means that inlining its behaviour to exactly match
isset() isn't logical.
For example, we can roughly assert that empty() = ! isset()
. This holds true
with the current semantics proposed by this RFC:
$defined = 1;
// $undefined;
var_dump(empty($defined, $undefined) === ! isset($defined, $undefined)); // bool(true)
If empty()'s arguments were logically AND'ed together, then the above assertion would
not hold true.
So those are the two arguments I'm aware of - if anyone in the -1 camp has any
other reasons, then please do raise them!
Thanks,
Tom
Hello PHP Internals!
I'd like to put the variadic empty() RFC to vote.
RFC: https://wiki.php.net/rfc/variadic_empty
Voting will finish in 14 days time on March 21st.
Thanks,
Tom
Hey PHP Internals,
I'm not entirely sure why
people are against it - and no one seems to want to debate it either.
I think these were covered in the discussion phase, but I will
reiterate the reasons I voted against it for clarity.
The falsy semantics of empty() means that inlining its behaviour to exactly match
isset() isn't logical.
The problem isn't so much that the behaviour doesn't match some other
pattern in PHP; the problem is that the function doesn't do what its
name says it does.
"if any arguments passed into empty() are considered falsy, then true
will be returned"
i.e. it doesn't check whether the arguments are 'empty', it's checking
whether they are 'all set and not falsy'. Having a function do
something different to what it's name suggests will lead to it being
used incorrectly a lot of the time.
The other reason I voted no, is that I just don't think this adds
enough to the language to be implemented in core. For at least two of
the examples in the RFC the desired functionality could be implemented
in userland.
The size of the PHP core codebase is already unwieldy. I think any
suggested addition needs to have a clear advantage over being
implemented in userland
cheers
Dan
Hey PHP Internals,
So there hasn't been much discussion on this RFC, and yet a lot of people have
voted -1 on it. This is a little disappointing because I'm not entirely sure why
people are against it - and no one seems to want to debate it either.
IMO, because it's not obvious whether it is all empty, or atleast
one empty. The same argument we had before, when we expanded isset() to
be variadic. We had the same discussion then, resulting on keeping
empty() as it is.
One discussion 11 years ago:
http://marc.info/?l=php-internals&m=109836951711930
I can't find the discussion prior to that though.
cheers,
Derick
Hey Internals,
I'd like to put the variadic empty() RFC to vote.
RFC: https://wiki.php.net/rfc/variadic_empty
Voting will finish in 14 days time on March 21st.
Voting has now ended with a 26:26 yes/no split. This means the RFC has
has been declined (namely surrounding the ambiguity of what semantics
empty() should have).
Thanks to all who participated in the discussions and voting of this RFC!
-Tom