Skip to content

Commit f278d10

Browse files
committed
Fix appending to arrays in PHP 5.6 and 7.0
1 parent db793cc commit f278d10

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/main/php/lang/ast/emit/PHP56.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected function emitConst($node) {
109109
}
110110

111111
protected function emitAssignment($node) {
112-
if ('[' === $node->value[0]->symbol->id) {
112+
if ('array' === $node->value[0]->arity) {
113113
$this->out->write('list(');
114114
$this->arguments($node->value[0]->value);
115115
$this->out->write(')');

src/main/php/lang/ast/emit/PHP70.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function catches($catch) {
3232
}
3333

3434
protected function emitAssignment($node) {
35-
if ('[' === $node->value[0]->symbol->id) {
35+
if ('array' === $node->value[0]->arity) {
3636
$this->out->write('list(');
3737
$this->arguments($node->value[0]->value);
3838
$this->out->write(')');

src/test/php/lang/ast/unittest/emit/ArraysTest.class.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,16 @@ public function run() {
3636

3737
$this->assertEquals([1, 2, 3], $r);
3838
}
39+
40+
#[@test]
41+
public function destructuring() {
42+
$r= $this->run('class <T> {
43+
public function run() {
44+
[$a, $b]= [1, 2];
45+
return [$a, $b];
46+
}
47+
}');
48+
49+
$this->assertEquals([1, 2], $r);
50+
}
3951
}

0 commit comments

Comments
 (0)