rfc:variadic_empty

Differences

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

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
rfc:variadic_empty [2015/02/20 11:46] – created tpuntrfc:variadic_empty [2015/03/28 15:54] tpunt
Line 1: Line 1:
-====== PHP RFC: Your Title Here ======+====== PHP RFC: Make empty() a Variadic ======
   * Version: 0.1   * Version: 0.1
   * 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: 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 make the ''empty'' language construct accept any number of arguments.+This RFC aims make ''empty()'' have a variable arity.
  
 <code php> <code php>
-// current usage 1: +// example current usage #1: 
-if (empty($a) || empty($b) || empty($c)) { +if (empty($a) || empty($b) || empty($c)) {}
-    // +
-}+
  
-// proposed usage 1+// example current usage #2
-if (empty($a$b$c)) { +if (!empty($a) && !empty($b) && !empty($c)) {}
-    // error here +
-}+
  
-// current usage 2+// new proposed usage #1
-if (!empty($a) && !empty($b) && !empty($c)) { +if (empty($a$b$c)) {}
-    // all good! +
-}+
  
-// proposed usage 2: +// new proposed usage #2: 
-if (!empty($a, $b, $c)) { +if (!empty($a, $b, $c)) {}
-    // all good! +
-}+
 </code> </code>
  
 ===== Proposal ===== ===== Proposal =====
-By making ''empty()'' to accept a variable arity, we can...+The proposal is to change ''empty()'' so that it can accept multiple argumentsThis will enable developers to write more compact code when checking for the emptiness of multiple expressions.
  
-===== Backward Incompatible Changes ===== +As the above snippet demonstratesthe 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 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).
-What breaksand what is the justification for it?+
  
-===== Proposed PHP Version(s) ===== +===== Justification =====
-List the proposed PHP versions that the feature will be included in.  Use relative versions such as "next PHP 5.x" or "next PHP 5.x.y".+
  
-===== RFC Impact ===== +In PHP, it is not uncommon to see conditionals consisting of multiple ''empty()'' invocationsThis is evident by simply browsing through some popular open source projects:
-==== To SAPIs ==== +
-Describe the impact to CLI, Development web server, embedded PHP etc.+
  
-==== To Existing Extensions ==== +WordPress (( https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/template.php#L2007 )): 
-Will existing extensions be affected?+<code php> 
 +if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) ) 
 +</code> 
 +OpenCart (( https://github.com/opencart/opencart/blob/45fc863fa068d82b5280890e6466a198faa54bff/upload/admin/controller/openbay/ebay_profile.php#L128 )): 
 +<code php> 
 +if (empty($setting['dispatch_times']) || empty($setting['countries']) || empty($setting['returns'])){ 
 +</code> 
 +phpBB (( https://github.com/phpbb/phpbb/blob/040d451dcca9ae54d8f4b7bdd2f231033765a8f2/phpBB/phpbb/notification/method/jabber.php#L48 )): 
 +<code php> 
 +return !( 
 + empty($this->config['jab_enable']) || 
 + empty($this->config['jab_host']) || 
 + empty($this->config['jab_username']) || 
 + empty($this->config['jab_password']) || 
 + !@extension_loaded('xml'
 +); 
 +</code>
  
-==== To Opcache ==== +And so on...
-It is necessary to develop RFC's with opcache in mind, since opcache is a core extension distributed with PHP.+
  
-Please explain how you have verified your RFC'compatibility with opcache.+So this seems like quite a common need for users, and one that cannot be emulated in user-land code because of ''empty()'''behaviour of suppressing undefined variable errors.
  
-==== New Constants ==== +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]].
-Describe any new constants so they can be accurately and comprehensively explained in the PHP documentation.+
  
-==== php.ini Defaults ==== +===== Backward Incompatible Changes ===== 
-If there are any php.ini settings then list: +No BC breakages.
-  * hardcoded default values +
-  * php.ini-development values +
-  * php.ini-production values+
  
-===== Open Issues ===== +===== Proposed PHP Version(s) ===== 
-Make sure there are no open issues when the vote starts!+PHP 7.0
  
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
-List existing areas/features of PHP that will not be changed by the RFC.+The current functionality of ''empty()'' will be completely preserved.
  
-This helps avoid any ambiguityshows that you have thought deeply about the RFC's impact, and helps reduces mail list noise.+===== Vote ===== 
 +Because this is a language changea 2/3 majority is required. It is a simple yes/no vote on whether ''empty()'' should be made a variadic.
  
-===== Future Scope ===== +<doodle title="Make empty() a Variadic" auth="tpunt" voteType="single" closed="true"> 
-This sections details areas where the feature might be improved in future, but that are not currently proposed in this RFC.+   * Yes 
 +   * No 
 +</doodle>
  
-===== Proposed Voting Choices ===== +Voting starts on 2015-03-07 and ends on 2015-03-21.
-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 ===== ===== 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 by 127.0.0.1