diff --git a/node/expr/t_array_dim_fetch_test.go b/node/expr/t_array_dim_fetch_test.go new file mode 100644 index 0000000..ce58542 --- /dev/null +++ b/node/expr/t_array_dim_fetch_test.go @@ -0,0 +1,74 @@ +package expr_test + +import ( + "bytes" + "reflect" + "testing" + + "github.com/z7zmey/php-parser/node/expr" + + "github.com/kylelemons/godebug/pretty" + "github.com/z7zmey/php-parser/node/scalar" + + "github.com/z7zmey/php-parser/node" + "github.com/z7zmey/php-parser/node/stmt" + "github.com/z7zmey/php-parser/php5" + "github.com/z7zmey/php-parser/php7" +) + +func assertEqual(t *testing.T, expected interface{}, actual interface{}) { + if !reflect.DeepEqual(expected, actual) { + diff := pretty.Compare(expected, actual) + + if diff != "" { + t.Errorf("diff: (-expected +actual)\n%s", diff) + } else { + t.Errorf("expected and actual are not equal\n") + } + } +} + +func TestArrayDimFetch(t *testing.T) { + src := `1, &$b,);` + + expected := &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Expression{ + Expr: &expr.Array{ + Items: []node.Node{ + &expr.ArrayItem{ + ByRef: false, + Key: &scalar.Lnumber{Value: "1"}, + Val: &scalar.Lnumber{Value: "1"}, + }, + &expr.ArrayItem{ + ByRef: true, + Val: &expr.Variable{VarName: &node.Identifier{Value: "$b"}}, + }, + }, + }, + }, + }, + } + + actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php") + assertEqual(t, expected, actual) + + actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php") + assertEqual(t, expected, actual) +} diff --git a/php5/php5.go b/php5/php5.go index a6b8466..ea1a84f 100644 --- a/php5/php5.go +++ b/php5/php5.go @@ -6284,7 +6284,7 @@ yydefault: yyDollar = yyS[yypt-0 : yypt+1] //line php5/php5.y:3442 { - yyVAL.list = nil + yyVAL.list = []node.Node{} } case 480: yyDollar = yyS[yypt-2 : yypt+1] diff --git a/php5/php5.y b/php5/php5.y index 4c994c3..bfe3812 100644 --- a/php5/php5.y +++ b/php5/php5.y @@ -3440,7 +3440,7 @@ assignment_list_element: array_pair_list: /* empty */ - { $$ = nil } + { $$ = []node.Node{} } | non_empty_array_pair_list possible_comma { $$ = $1 } ;