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:08] 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;
 +// or we need to check it ourself
 +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 67: Line 95:
  
 ===== RFC Impact ===== ===== RFC Impact =====
-==== To SAPIs ==== 
-No impact 
- 
-==== To Existing Extensions ==== 
-No impact 
  
 ==== To Opcache ==== ==== To Opcache ====
  
 I am working on opcache compatibility. I am working on opcache compatibility.
- 
-==== New Constants ==== 
-None 
- 
-==== php.ini Defaults ==== 
-None 
  
 ===== Open Issues ===== ===== Open Issues =====
 None for now None for now
- 
-===== Unaffected PHP Functionality ===== 
-No BC break 
  
 ===== Future Scope ===== ===== Future Scope =====
- 
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
Line 117: Line 130:
 ===== Rejected Features ===== ===== Rejected Features =====
  
 +===== Changelog =====
 +
 +  * v0.1 - Initial version
rfc/list_default_value.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1