rfc:list_default_value
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:list_default_value [2015/11/07 17:38] – created reeze | rfc:list_default_value [2015/11/09 13:33] – reeze | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Default Value in List Syntax ====== | + | ====== PHP RFC: Default Value in List Assignment |
- | * Version: 0.9 | + | * Version: 0.1 |
* Date: 2015-11-08 | * Date: 2015-11-08 | ||
* Author: Reeze Xia, reeze@php.net | * Author: Reeze Xia, reeze@php.net | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
- | This is a suggested template for PHP Request for Comments | + | ===== Introduction ===== |
- | Read https:// | + | We could destruct variables from an array with [[http:// |
+ | For the similar purpose we introduced | ||
- | Quoting | + | Some clever users figured out some workaround like this |
- | > PHP is and should remain: | + | ===== Proposal ===== |
- | > 1) a pragmatic web-focused language | + | |
- | > 2) a loosely typed language | + | |
- | > 3) a language which caters to the skill-levels and platforms of a wide range of users | + | |
- | Your RFC should move PHP forward following his vision. As [[http:// | + | Support new syntax |
- | large chunk of our userbase, and not something that could be useful | + | |
- | extremely specialized edge cases [...] Make sure you think about the full context, the huge audience out there, the consequences of making the learning curve steeper with | + | |
- | every new feature, and the scope of the goodness that those new features bring." | + | |
- | ===== Introduction | + | <code php> |
- | The elevator pitch for the RFC. The first paragraph in this section will be slightly larger to give it emphasis; please write a good introduction. | + | list($a, $b=' |
+ | list($a, $b=' | ||
- | ===== Proposal ===== | ||
- | All the features and examples of the proposal. | ||
- | To [[http://news.php.net/php.internals/66051|paraphrase Zeev Suraski]], explain hows the proposal brings substantial | + | function say_hello() |
- | for inclusion | + | { |
+ | return " | ||
+ | } | ||
+ | $name = ' | ||
+ | list($a=say_hello(), | ||
+ | |||
+ | list($a, list($b=1, $c=2)) = [1]; // a = 1, b = 1, c = 2 | ||
+ | |||
+ | </ | ||
+ | |||
+ | The assignment could be considered as a shortcut for: | ||
+ | |||
+ | < | ||
+ | |||
+ | list($a, $b=' | ||
+ | |||
+ | // equals | ||
+ | |||
+ | $a = $arr[0]; | ||
+ | $b = isset($arr[1]) ? $arr[1] : ' | ||
+ | </ | ||
+ | |||
+ | This seems not a lot of work than the new syntax. But sometimes we need to destruct nested array and there are morn than two variables, anyway list() itself is designed to avoid assign by hand for short and clean code. | ||
+ | |||
+ | |||
+ | The syntax is: | ||
+ | |||
+ | <code flex> | ||
+ | assignment_list_element: | ||
+ | variable | ||
+ | + | variable ' | ||
+ | | T_LIST ' | ||
+ | | /* empty */ | ||
+ | </ | ||
+ | |||
+ | The syntax is same as function' | ||
+ | |||
+ | |||
+ | We could also set default value in foreach list context: | ||
+ | |||
+ | <code php> | ||
+ | foreach($arr as list($k, list($v1=' | ||
+ | // do something | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | More case could be found from PR' | ||
- | Remember that the RFC contents should | + | This feature could also be found in [[https:// |
===== 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 7.1 |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
==== To SAPIs ==== | ==== To SAPIs ==== | ||
- | Describe the impact | + | No impact |
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
- | Will existing extensions be affected? | + | No impact |
==== 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's compatibility with opcache. | + | I am working on opcache |
==== New Constants ==== | ==== New Constants ==== | ||
- | Describe any new constants so they can be accurately and comprehensively explained in the PHP documentation. | + | None |
==== php.ini Defaults ==== | ==== php.ini Defaults ==== | ||
- | If there are any php.ini settings then list: | + | None |
- | * 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 ===== | ===== Unaffected PHP Functionality ===== | ||
- | List existing areas/ | + | No BC break |
- | + | ||
- | 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:// |
- | 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 90: | Line 125: | ||
===== References ===== | ===== References ===== | ||
- | Links to external references, discussions or RFCs | + | |
+ | * Javascript destructing: | ||
+ | * Clojure destructing [[https:// | ||
===== 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