rfc:foreachlist
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
rfc:foreachlist [2012/07/18 11:42] laruence |
rfc:foreachlist [2017/09/22 13:28] (current) |
||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2011-07-06 | * Date: 2011-07-06 | ||
* Author: Xinchen Hui < | * Author: Xinchen Hui < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 14: | Line 14: | ||
$users = array( | $users = array( | ||
array(' | array(' | ||
- | array(' | + | array(' |
); | ); | ||
Line 34: | Line 34: | ||
This RFC provides a behavior specification and implementation for this feature. | This RFC provides a behavior specification and implementation for this feature. | ||
- | |||
- | ===== Proposal ===== | ||
- | 1. ZEND_FE_FETCH | ||
- | <code php> | ||
- | <?php | ||
- | $rows = array(array(24, | ||
- | |||
- | foreach ($rows as list($a, $b)) { | ||
- | printf(" | ||
- | } | ||
- | |||
- | /** Output: | ||
- | a=>24, b=>2333 | ||
- | a=>31, b=>4666 | ||
- | */ | ||
- | </ | ||
- | |||
- | 2. ZEND_FE_FETCH_WITH_KEY | ||
- | <code php> | ||
- | <?php | ||
- | $rows = array(array(24, | ||
- | |||
- | foreach ($rows as $k => list($a, $b)) { | ||
- | printf(" | ||
- | } | ||
- | |||
- | /** Output: | ||
- | key:0, a=>24, b=>2333 | ||
- | key:1, a=>31, b=>4666 | ||
- | */ | ||
- | </ | ||
- | |||
- | Samples with generated opcodes: | ||
- | |||
- | list.php | ||
- | <code php> | ||
- | <?php | ||
- | foreach (array(array(1, | ||
- | echo $a, $b; | ||
- | } | ||
- | </ | ||
- | |||
- | < | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | 10 ASSIGN | ||
- | 11 FETCH_DIM_R | ||
- | 12 ASSIGN | ||
- | | ||
- | 14 ECHO !1 | ||
- | | ||
- | 16 > | ||
- | </ | ||
- | |||
- | list_with_key.php | ||
- | <code php> | ||
- | <?php | ||
- | $array = array( | ||
- | array(1, 2), | ||
- | array(3, 4) | ||
- | ); | ||
- | |||
- | foreach ($array as $k => list($a, $b)) { | ||
- | echo $k, $a, $b; | ||
- | } | ||
- | </ | ||
- | |||
- | < | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | 10 FETCH_DIM_R | ||
- | 11 ASSIGN | ||
- | 12 FETCH_DIM_R | ||
- | 13 ASSIGN | ||
- | 14 ASSIGN | ||
- | | ||
- | 16 ECHO !2 | ||
- | 17 ECHO !3 | ||
- | | ||
- | 19 > | ||
- | 10 20 > RETURN | ||
- | </ | ||
===== Implementation details of the RFC ===== | ===== Implementation details of the RFC ===== | ||
Line 143: | Line 45: | ||
</ | </ | ||
- | Without the rules: | + | Without the new patch: |
< | < | ||
PHP Parse error: | PHP Parse error: | ||
</ | </ | ||
- | With the rules: | + | With the new patch: |
< | < | ||
PHP Fatal error: | PHP Fatal error: | ||
Line 158: | Line 60: | ||
It is possible to add support of the silent token in the new context: | It is possible to add support of the silent token in the new context: | ||
<code php> | <code php> | ||
- | foreach (array(array(1, | + | $array = array(array(1, |
- | } | + | foreach ($array |
+ | } 1 | ||
</ | </ | ||
- | In case we want this, an additional patch will be provided. | + | ===== Patches ===== |
+ | * foreach list: https:// | ||
+ | * foreach list with supporting of silent token: https:// | ||
+ | ===== Vote ===== | ||
+ | <doodle | ||
+ | title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
- | Opcodes generated: | + | <doodle |
- | + | title=" | |
- | list_with_silent.php | + | |
- | <code php> | + | |
- | <?php | + | </doodle> |
- | foreach | + | |
- | echo $a, $b; // Without the silent token, there will be a notice since the third nested array has no second item. | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | < | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | 10 > | + | |
- | 11 BEGIN_SILENCE | + | |
- | 12 FETCH_DIM_R | + | |
- | 13 FETCH_W | + | |
- | 14 ASSIGN | + | |
- | 15 FETCH_DIM_R | + | |
- | 16 FETCH_W | + | |
- | 17 ASSIGN | + | |
- | 18 END_SILENCE | + | |
- | | + | |
- | 20 ECHO !1 | + | |
- | | + | |
- | 22 > | + | |
- | | + | |
- | </ | + | |
- | + | ||
- | ===== Patches ===== | + | |
- | | + | |
- | | + | |
- | ===== Tests ===== | + | |
- | * http:// | + | |
- | * http:// | + | |
===== Changelog ===== | ===== Changelog ===== | ||
* 2011-07-06 Xinchen Hui: Initial RFC creation | * 2011-07-06 Xinchen Hui: Initial RFC creation | ||
Line 215: | Line 88: | ||
* 2011-07-08 Xinchen Hui: Added opcodes with silent token | * 2011-07-08 Xinchen Hui: Added opcodes with silent token | ||
* 2011-07-24 Xinchen Hui: Updated patches that fixed a bug: znode-> | * 2011-07-24 Xinchen Hui: Updated patches that fixed a bug: znode-> | ||
+ | * 2012-07-18 Phidev: Rewrote the RFC | ||
+ | * 2012-08-18 Xinchen Hui: Open voting | ||
+ | * 2012-08-25 Xinchen Hui: Close voting | ||
rfc/foreachlist.1342611773.txt.gz · Last modified: 2017/09/22 13:28 (external edit)