rfc:variadic_empty

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
rfc:variadic_empty [2015/02/21 03:11]
tpunt
rfc:variadic_empty [2015/03/26 08:55]
tpunt
Line 3: Line 3:
   * Date: 2015-02-20   * Date: 2015-02-20
   * Author: Thomas Punt, tpunt@hotmail.co.uk   * Author: Thomas Punt, tpunt@hotmail.co.uk
-  * Status: ​Draft+  * Status: ​Closed
   * First Published at: http://​wiki.php.net/​rfc/​variadic_empty   * First Published at: http://​wiki.php.net/​rfc/​variadic_empty
  
 ===== Introduction ===== ===== Introduction =====
-This RFC aims to make the ''​empty'' ​language construct accept any number of arguments.+This RFC aims make ''​empty()'' ​have a variable arity.
  
 <code php> <code php>
Line 16: Line 16:
 if (!empty($a) && !empty($b) && !empty($c)) {} if (!empty($a) && !empty($b) && !empty($c)) {}
  
-// new example ​usage #1:+// new proposed ​usage #1:
 if (empty($a, $b, $c)) {} if (empty($a, $b, $c)) {}
  
-// new example ​usage #2:+// new proposed ​usage #2:
 if (!empty($a, $b, $c)) {} if (!empty($a, $b, $c)) {}
 </​code>​ </​code>​
  
 ===== Proposal ===== ===== Proposal =====
-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.+The proposal is to change ''​empty()'' ​so that it can accept multiple arguments. This 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 ​togetherThis behaviour seems to be the most usefuland given that ''​empty()'' ​performs a reverse check to ''​isset()''​, it should have reversed ​semantics ​in order to make it inline. ...+As the above snippet demonstrates,​ the semantics of a variadic ''​empty()''​ should be the equivalent to logically OR'​ing ​together ​multiple ''​empty()''​ invocations. ​Thusif //any// arguments passed into ''​empty()'' ​are considered falsy, then **true** will be returned; if //no// arguments are considered empty, then **false** is returned. This behaviour is the most logical (given ​''​empty()''​'s falsy semantics) and seems to be the most prevalent usage of multiple empty checks in user-land code (therefore being the most beneficial behaviour).
  
 ===== Justification ===== ===== Justification =====
  
-==== Common ==== 
 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: 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 (( https://​github.com/​WordPress/​WordPress/​blob/​master/​wp-admin/​includes/​template.php#​L1963 ))+WordPress (( https://​github.com/​WordPress/​WordPress/​blob/​master/​wp-admin/​includes/​template.php#​L2007 )):
 <code php> <code php>
 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['​content'​] ) ) if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['​content'​] ) )
 </​code>​ </​code>​
-  * OpenCart (( https://​github.com/​opencart/​opencart/​blob/​45fc863fa068d82b5280890e6466a198faa54bff/​upload/​admin/​controller/​openbay/​ebay_profile.php#​L128 ))+OpenCart (( https://​github.com/​opencart/​opencart/​blob/​45fc863fa068d82b5280890e6466a198faa54bff/​upload/​admin/​controller/​openbay/​ebay_profile.php#​L128 )):
 <code php> <code php>
 if (empty($setting['​dispatch_times'​]) || empty($setting['​countries'​]) || empty($setting['​returns'​])){ if (empty($setting['​dispatch_times'​]) || empty($setting['​countries'​]) || empty($setting['​returns'​])){
 </​code>​ </​code>​
-  * phpBB (( https://​github.com/​phpbb/​phpbb/​blob/​040d451dcca9ae54d8f4b7bdd2f231033765a8f2/​phpBB/​phpbb/​notification/​method/​jabber.php#​L48 ))+phpBB (( https://​github.com/​phpbb/​phpbb/​blob/​040d451dcca9ae54d8f4b7bdd2f231033765a8f2/​phpBB/​phpbb/​notification/​method/​jabber.php#​L48 )):
 <code php> <code php>
 return !( return !(
- empty($this->​config['​jab_enable'​]) || + empty($this->​config['​jab_enable'​]) || 
- empty($this->​config['​jab_host'​]) || + empty($this->​config['​jab_host'​]) || 
- empty($this->​config['​jab_username'​]) || + empty($this->​config['​jab_username'​]) || 
- empty($this->​config['​jab_password'​]) || + empty($this->​config['​jab_password'​]) || 
- !@extension_loaded('​xml'​) + !@extension_loaded('​xml'​) 
- );+);
 </​code>​ </​code>​
-  * And so on... 
  
-So this seems like quite a common need for users.+And so on...
  
-The second justification is that it will make ''​empty()''​ more inline with the  ''​isset()'',​ which is good for the principle of least surprise+So this seems like quite a common need for users, and one that cannot be emulated in user-land code because of ''​empty()'''​s behaviour of suppressing undefined variable errors. 
 + 
 +This change ​will also make ''​empty()''​ more inline with the not-too-dissimilar ​''​isset()'',​ which is good for [[http://​en.wikipedia.org/​wiki/​Principle_of_least_astonishment|POLA]].
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 62: Line 62:
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
 PHP 7.0 PHP 7.0
- 
-===== RFC Impact ===== 
-==== To SAPIs ==== 
-None. 
- 
-==== To Existing Extensions ==== 
-None. 
- 
-==== To Opcache ==== 
-None. 
- 
-==== New Constants ==== 
-None. 
- 
-==== php.ini Defaults ==== 
-None. 
- 
-===== Open Issues ===== 
-None. 
  
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
 The current functionality of ''​empty()''​ will be completely preserved. The current functionality of ''​empty()''​ will be completely preserved.
  
-===== Future Scope ===== +===== Vote ===== 
-None that I can think of.+Because this is a language change, a 2/3 majority is required. It is a simple yes/no vote on whether ''​empty()''​ should be made a variadic.
  
-===== Proposed Voting Choices ===== +<doodle title="Make empty() a Variadic"​ auth="​tpunt"​ voteType="​single"​ closed="​true">​ 
-Include these so readers know where you are heading and can discuss the proposed voting options.+   * Yes 
 +   * No 
 +</​doodle>​
  
-State whether this project requires a 2/3 or 50%+1 majority (see [[voting]])+Voting starts on 2015-03-07 and ends on 2015-03-21.
  
 ===== Patches and Tests ===== ===== 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. 
- 
-===== Implementation ===== 
-After the project is implemented,​ this section should contain ​ 
-  - the version(s) it was merged to 
-  - a link to the git commit(s) 
-  - a link to the PHP manual entry for the feature 
- 
-===== References ===== 
-Links to external references, discussions or RFCs 
  
-===== Rejected Features ===== +PR: https://​github.com/​php/​php-src/​pull/​1109
-Keep this updated with features that were discussed on the mail lists.+
rfc/variadic_empty.txt · Last modified: 2017/09/22 13:28 (external edit)