rfc:variadic_empty

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:variadic_empty [2015/02/21 04:54] tpuntrfc:variadic_empty [2017/09/22 13:28] (current) – external edit 127.0.0.1
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: Under Discussion+  * Status: Declined
   * 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 enable ''empty()'' to accept any number of arguments.+This RFC aims make ''empty()'' have a variable arity.
  
 <code php> <code php>
Line 24: Line 24:
  
 ===== Proposal ===== ===== Proposal =====
-The proposal is to change ''empty()'' so that it has a variable arity. This 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 together multiple ''empty()'' invocations. Thus, if //any// arguments passed into ''empty()'' are considered falsy, then **true** will be returned - otherwise, **false** is returned. This behaviour seems to be the most prevalent usage of multiple empty checks in a condition, therefore benefitting the most end users.+As the above snippet demonstrates, the semantics of a variadic ''empty()'' should be the equivalent to logically OR'ing together multiple ''empty()'' invocations. Thus, if //any// arguments passed into ''empty()'' are considered falsy, then **true** will be returned; if //no// arguments are considered emptythen **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 =====
Line 32: Line 32:
 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'] ) )
Line 43: Line 43:
 <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 one that cannot be emulated in user-land code because of ''empty()'''s behaviour of suppressing undefined variablesAlso, it will make ''empty()'' more inline with the not-too-disimillar ''isset()'', which is good for the [[http://en.wikipedia.org/wiki/Principle_of_least_astonishment|Principle of Least Astonishment]] (mainly aimed at neophyte developers).+And so on... 
 + 
 +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 63: Line 66:
 The current functionality of ''empty()'' will be completely preserved. The current functionality of ''empty()'' will be completely preserved.
  
-===== Proposed Voting Choices ===== +===== Vote ===== 
-State whether this project requires a 2/3 or 50%+1 majority (see [[voting]])+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. 
 + 
 +<doodle title="Make empty() a Variadic" auth="tpunt" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle> 
 + 
 +Voting starts on 2015-03-07 and ends on 2015-03-21.
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
  
 PR: https://github.com/php/php-src/pull/1109 PR: https://github.com/php/php-src/pull/1109
rfc/variadic_empty.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1