rfc:list_default_value

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
Next revisionBoth sides next revision
rfc:list_default_value [2015/11/09 13:03] reezerfc:list_default_value [2015/11/09 13:53] reeze
Line 1: Line 1:
-====== PHP RFC:  Default Value in List Syntax ======+====== PHP RFC:  Default Value in List Assignment Syntax ======
   * Version: 0.1   * Version: 0.1
   * Date: 2015-11-08   * Date: 2015-11-08
   * Author: Reeze Xia, reeze@php.net   * Author: Reeze Xia, reeze@php.net
-  * Status: Draft+  * Status: Under Discussion
   * First Published at: http://wiki.php.net/rfc/list_default_value   * First Published at: http://wiki.php.net/rfc/list_default_value
  
Line 18: Line 18:
  
 <code php> <code php>
 +// basic syntax
 list($a, $b='default') = [1];      // a = 1, b = 'default' list($a, $b='default') = [1];      // a = 1, b = 'default'
 list($a, $b='default') = [1, 2];  // a = 1, b = 2 list($a, $b='default') = [1, 2];  // a = 1, b = 2
 +
 +//  comparation
 +list($a, list($b=1, $c=2) = $arr;
 +// opposite we need to
 +if (!isset($arr[1][0])) {
 +    $arr[1][0] = 1;
 +}
 +if (!isset($arr[1][1])) {
 +    $arr[1][0] = 2;
 +}
 +
 +$list($a, list($b, $c)) = $arr;
 +
 +
 +// other examples
 +function say_hello()
 +{
 +    return "Hello";
 +}
 +$name = 'PHP';
 +list($a=say_hello(), $b=$name."7.0") = []; // a = 'Hello', b = 'PHP7.0'
  
 list($a, list($b=1, $c=2)) = [1]; // a = 1, b = 1, c = 2 list($a, list($b=1, $c=2)) = [1]; // a = 1, b = 1, c = 2
 +
 </code> </code>
  
-The previous assignment could be considered as a shortcut for:+The assignment could be considered as a shortcut for:
  
 <code php> <code php>
 +
 +list($a, $b='deafult') = $arr;
 +
 +// equals
 +
 $a = $arr[0]; $a = $arr[0];
 $b = isset($arr[1]) ? $arr[1] : 'default'; $b = isset($arr[1]) ? $arr[1] : 'default';
Line 57: Line 85:
 More case could be found from PR's tests:  [[https://github.com/php/php-src/pull/1623/files]] More case could be found from PR's tests:  [[https://github.com/php/php-src/pull/1623/files]]
  
-This feature could be find in [[https://clojurebridge.github.io/community-docs/docs/clojure/destructuring/|Clojure]] and [[https://hacks.mozilla.org/2015/05/es6-in-depth-destructuring/|Javascript]].  +This feature could also be found in [[https://clojurebridge.github.io/community-docs/docs/clojure/destructuring/|Clojure]] and [[https://hacks.mozilla.org/2015/05/es6-in-depth-destructuring/|Javascript]] for destructing
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
-What breaks, and what is the justification for it?+ 
 +No BC break.
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
-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".+PHP 7.1
  
 ===== RFC Impact ===== ===== RFC Impact =====
-==== To SAPIs ==== 
-Describe the impact to CLI, Development web server, embedded PHP etc. 
- 
-==== To Existing Extensions ==== 
-Will existing extensions be affected? 
  
 ==== To Opcache ==== ==== To Opcache ====
-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. +I am working on opcache compatibility.
- +
-==== New Constants ==== +
-Describe any new constants so they can be accurately and comprehensively explained in the PHP documentation. +
- +
-==== php.ini Defaults ==== +
-If there are any php.ini settings then list: +
-  * hardcoded default values +
-  * php.ini-development values +
-  * php.ini-production values+
  
 ===== Open Issues ===== ===== Open Issues =====
-Make sure there are no open issues when the vote starts! +None for now
- +
-===== Unaffected PHP Functionality ===== +
-List existing areas/features of PHP that will not be changed by the RFC. +
- +
-This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise.+
  
 ===== Future Scope ===== ===== Future Scope =====
-This sections details areas where the feature might be improved in future, but that are not currently proposed in this RFC. 
  
 ===== Proposed Voting Choices ===== ===== 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]])+* Whether accept the RFC for PHP 7.1 
 + 
 +This project requires a 2/3 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.+* Patch: [[https://github.com/php/php-src/pull/1623]]
  
-Make it clear if the patch is intended to be the final patch, or is just a prototype.+I am working on opcache compatibility
  
 ===== Implementation ===== ===== Implementation =====
Line 122: Line 129:
  
 ===== Rejected Features ===== ===== Rejected Features =====
-Keep this updated with features that were discussed on the mail lists.+ 
 +===== Changelog ===== 
 + 
 +  * v0.1 - Initial version
rfc/list_default_value.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1