Skip to content

Commit 589756c

Browse files
Allow arbitrary expressions for key
1 parent 3f62207 commit 589756c

File tree

5 files changed

+314
-10
lines changed

5 files changed

+314
-10
lines changed

Zend/tests/list_keyed_ArrayAccess.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ var_dump($good, $happy);
1212

1313
echo PHP_EOL;
1414

15+
$stdClassCollection = new SplObjectStorage;
16+
$foo = new StdClass;
17+
$stdClassCollection[$foo] = "foo";
18+
$bar = new StdClass;
19+
$stdClassCollection[$bar] = "bar";
20+
21+
list($foo => $fooStr, $bar => $barStr) = $stdClassCollection;
22+
var_dump($fooStr, $barStr);
23+
24+
echo PHP_EOL;
25+
1526
class IndexPrinter implements ArrayAccess
1627
{
1728
public function offsetGet($offset) {
@@ -36,5 +47,8 @@ list("123" => $x) = $op;
3647
string(3) "bad"
3748
string(3) "sad"
3849

50+
string(3) "foo"
51+
string(3) "bar"
52+
3953
GET int(123)
4054
GET string(3) "123"
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,26 @@ list() with constant keys
55

66
$arr = [
77
1 => "one",
8-
2 => "two"
8+
2 => "two",
9+
3 => "three"
910
];
1011

1112
const COMPILE_TIME_RESOLVABLE = 1;
1213

1314
define('PROBABLY_NOT_COMPILE_TIME_RESOLVABLE', file_get_contents("data:text/plain,2"));
1415

16+
$probablyNotCompileTimeResolvable3 = cos(0) * 3;
17+
1518
list(
1619
COMPILE_TIME_RESOLVABLE => $one,
17-
PROBABLY_NOT_COMPILE_TIME_RESOLVABLE => $two
20+
PROBABLY_NOT_COMPILE_TIME_RESOLVABLE => $two,
21+
$probablyNotCompileTimeResolvable3 => $three
1822
) = $arr;
1923

20-
var_dump($one, $two);
24+
var_dump($one, $two, $three);
2125

2226
?>
2327
--EXPECTF--
2428
string(3) "one"
2529
string(3) "two"
30+
string(5) "three"

Zend/zend_language_parser.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,9 +1199,9 @@ keyed_assignment_list:
11991199
;
12001200

12011201
keyed_assignment_list_element:
1202-
scalar T_DOUBLE_ARROW variable
1202+
expr T_DOUBLE_ARROW variable
12031203
{ $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $3, $1); }
1204-
| scalar T_DOUBLE_ARROW T_LIST '(' assignment_list ')'
1204+
| expr T_DOUBLE_ARROW T_LIST '(' assignment_list ')'
12051205
{ $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $5, $1); }
12061206
;
12071207

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,7 @@ ZEND_VM_HANDLER(97, ZEND_FETCH_OBJ_UNSET, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV)
20622062
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
20632063
}
20642064

2065-
ZEND_VM_HANDLER(98, ZEND_FETCH_LIST, CONST|TMPVAR|CV, CONST|TMPVAR)
2065+
ZEND_VM_HANDLER(98, ZEND_FETCH_LIST, CONST|TMPVAR|CV, CONST|TMPVAR|CV)
20662066
{
20672067
USE_OPLINE
20682068
zend_free_op free_op1;

0 commit comments

Comments
 (0)