This is an old revision of the document!

PHP RFC: Make empty() a Variadic


This RFC aims to make the empty language construct accept any number of arguments.

// example current usage #1:
if (empty($a) || empty($b) || empty($c)) {}
// example current usage #2:
if (!empty($a) && !empty($b) && !empty($c)) {}
// new example usage #1:
if (empty($a, $b, $c)) {}
// new example usage #2:
if (!empty($a, $b, $c)) {}


This RFC proposes to change empty() to have a variable arity, which will enable developers to write more compact code when checking for the emptiness of multiple expressions.

As the above snippet demonstrates, the semantics of a variadic empty() should be the equivalent to logically OR'ing multiple empty() invocations together. This behaviour seems to be the most useful, and given that empty() performs a reverse check to isset(), it should have reversed semantics in order to make it inline. ...



In PHP, it is not uncommon to see conditionals consisting of multiple empty() invocations. This is evident by simply browsing through some popular open source projects:

  • WordPress 1)
if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
  • OpenCart 2)
if (empty($setting['dispatch_times']) || empty($setting['countries']) || empty($setting['returns'])){
  • phpBB 3)
return !(
			empty($this->config['jab_enable']) ||
			empty($this->config['jab_host']) ||
			empty($this->config['jab_username']) ||
			empty($this->config['jab_password']) ||
  • And so on...

So this seems like quite a common need for users.

The second justification is that it will make empty() more inline with the isset(), which is good for the principle of least surprise

Backward Incompatible Changes

No BC breakages.

Proposed PHP Version(s)

PHP 7.0

RFC Impact



To Existing Extensions


To Opcache


New Constants


php.ini Defaults


Open Issues


Unaffected PHP Functionality

The current functionality of empty() will be completely preserved.

Future Scope

None that I can think of.

Proposed Voting Choices

Include these so readers know where you are heading and can discuss the proposed voting options.

State whether this project requires a 2/3 or 50%+1 majority (see voting)

Patches and Tests

Links to any external patches and tests go here.

If there is no patch, make it clear who will create a patch, or whether a volunteer to help with implementation is needed.

Make it clear if the patch is intended to be the final patch, or is just a prototype.


After the project is implemented, this section should contain

  1. the version(s) it was merged to
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature


Links to external references, discussions or RFCs

Rejected Features

Keep this updated with features that were discussed on the mail lists.

rfc/variadic_empty.1424488279.txt.gz · Last modified: 2017/09/22 13:28 (external edit)