From d9a23f2dc7959c00387d1839dfa43de1b386b89c Mon Sep 17 00:00:00 2001 From: nikic Date: Thu, 11 Aug 2011 08:13:01 +0200 Subject: [PATCH] Add specialized constructors for Expr_Array*, make Variable an Expr --- grammar/zend_language_parser.phpy | 38 +++++++++++------------ lib/PHPParser/Node/Expr/Array.php | 15 +++++++++ lib/PHPParser/Node/Expr/ArrayCast.php | 15 +++++++++ lib/PHPParser/Node/Expr/ArrayDimFetch.php | 19 +++++++++++- lib/PHPParser/Node/Expr/ArrayItem.php | 25 +++++++++++++-- lib/PHPParser/Node/Variable.php | 10 +++--- lib/PHPParser/Parser.php | 38 +++++++++++------------ lib/PHPParser/ParserDebug.php | 38 +++++++++++------------ lib/PHPParser/PrettyPrinter/Zend.php | 8 ++--- test/PHPParser/Tests/NodeDumperTest.php | 12 ++++--- 10 files changed, 143 insertions(+), 75 deletions(-) diff --git a/grammar/zend_language_parser.phpy b/grammar/zend_language_parser.phpy index 1f494132..3537ac72 100644 --- a/grammar/zend_language_parser.phpy +++ b/grammar/zend_language_parser.phpy @@ -512,14 +512,14 @@ expr: | T_INT_CAST expr { $$ = Expr_IntCast[expr: $2]; } | T_DOUBLE_CAST expr { $$ = Expr_DoubleCast[expr: $2]; } | T_STRING_CAST expr { $$ = Expr_StringCast[expr: $2]; } - | T_ARRAY_CAST expr { $$ = Expr_ArrayCast[expr: $2]; } + | T_ARRAY_CAST expr { $$ = Expr_ArrayCast[$2]; } | T_OBJECT_CAST expr { $$ = Expr_ObjectCast[expr: $2]; } | T_BOOL_CAST expr { $$ = Expr_BoolCast[expr: $2]; } | T_UNSET_CAST expr { $$ = Expr_UnsetCast[expr: $2]; } | T_EXIT exit_expr { $$ = Expr_Exit[expr: $2]; } | '@' expr { $$ = Expr_ErrorSuppress[expr: $2]; } | scalar { $$ = $1; } - | T_ARRAY '(' array_pair_list ')' { $$ = Expr_Array[items: $3]; } + | T_ARRAY '(' array_pair_list ')' { $$ = Expr_Array[$3]; } | '`' backticks_expr '`' { $$ = Expr_ShellExec[parts: $2]; } | T_PRINT expr { $$ = Expr_Print[expr: $2]; } | T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars '{' inner_statement_list '}' @@ -589,8 +589,8 @@ object_access_for_dcnr: { $$ = Expr_PropertyFetch[var: $1, name: $3]; } | object_access_for_dcnr T_OBJECT_OPERATOR object_property { $$ = Expr_PropertyFetch[var: $1, name: $3]; } - | object_access_for_dcnr '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; } - | object_access_for_dcnr '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; } + | object_access_for_dcnr '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[$1, $3]; } + | object_access_for_dcnr '{' expr '}' { $$ = Expr_ArrayDimFetch[$1, $3]; } ; exit_expr: @@ -632,7 +632,7 @@ static_scalar: /* compile-time evaluated scalars */ | name { $$ = Expr_ConstFetch[name: $1]; } | '+' static_scalar { $$ = Expr_UnaryPlus[expr: $2]; } | '-' static_scalar { $$ = Expr_UnaryMinus[expr: $2]; } - | T_ARRAY '(' static_array_pair_list ')' { $$ = Expr_Array[items: $3]; } + | T_ARRAY '(' static_array_pair_list ')' { $$ = Expr_Array[$3]; } | class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { $$ = Expr_ClassConstFetch[class: $1, name: $3]; } ; @@ -661,8 +661,8 @@ non_empty_static_array_pair_list: ; static_array_pair: - static_scalar T_DOUBLE_ARROW static_scalar { $$ = Expr_ArrayItem[key: $1, value: $3, byRef: false]; } - | static_scalar { $$ = Expr_ArrayItem[key: null, value: $1, byRef: false]; } + static_scalar T_DOUBLE_ARROW static_scalar { $$ = Expr_ArrayItem[$1, $3, false]; } + | static_scalar { $$ = Expr_ArrayItem[null, $1, false]; } ; variable: @@ -682,8 +682,8 @@ object_access: object_access_arrayable: variable T_OBJECT_OPERATOR object_property { $$ = Expr_PropertyFetch[var: $1, name: $3]; } - | object_access_arrayable '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; } - | object_access_arrayable '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; } + | object_access_arrayable '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[$1, $3]; } + | object_access_arrayable '{' expr '}' { $$ = Expr_ArrayDimFetch[$1, $3]; } ; variable_without_objects: @@ -709,13 +709,13 @@ static_property_with_arrays: { $$ = Expr_StaticPropertyFetch[class: $1, name: $5]; } | reference_variable T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}' { $$ = Expr_StaticPropertyFetch[class: $1, name: $5]; } - | static_property_with_arrays '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; } - | static_property_with_arrays '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; } + | static_property_with_arrays '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[$1, $3]; } + | static_property_with_arrays '{' expr '}' { $$ = Expr_ArrayDimFetch[$1, $3]; } ; reference_variable: - reference_variable '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; } - | reference_variable '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; } + reference_variable '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[$1, $3]; } + | reference_variable '{' expr '}' { $$ = Expr_ArrayDimFetch[$1, $3]; } | T_VARIABLE { $$ = Variable[parseVar($1)]; } | '$' '{' expr '}' { $$ = Variable[$3]; } ; @@ -753,10 +753,10 @@ non_empty_array_pair_list: ; array_pair: - expr T_DOUBLE_ARROW expr { $$ = Expr_ArrayItem[key: $1, value: $3, byRef: false]; } - | expr { $$ = Expr_ArrayItem[key: null, value: $1, byRef: false]; } - | expr T_DOUBLE_ARROW '&' variable { $$ = Expr_ArrayItem[key: $1, value: $4, byRef: true]; } - | '&' variable { $$ = Expr_ArrayItem[key: null, value: $2, byRef: true]; } + expr T_DOUBLE_ARROW expr { $$ = Expr_ArrayItem[$1, $3, false]; } + | expr { $$ = Expr_ArrayItem[null, $1, false]; } + | expr T_DOUBLE_ARROW '&' variable { $$ = Expr_ArrayItem[$1, $4, true]; } + | '&' variable { $$ = Expr_ArrayItem[null, $2, true]; } ; encaps_list: @@ -768,11 +768,11 @@ encaps_list: encaps_var: T_VARIABLE { $$ = Variable[parseVar($1)]; } - | T_VARIABLE '[' encaps_var_offset ']' { $$ = Expr_ArrayDimFetch[var: Variable[parseVar($1)], dim: $3]; } + | T_VARIABLE '[' encaps_var_offset ']' { $$ = Expr_ArrayDimFetch[Variable[parseVar($1)], $3]; } | T_VARIABLE T_OBJECT_OPERATOR T_STRING { $$ = Expr_PropertyFetch[var: Variable[parseVar($1)], name: $3]; } | T_DOLLAR_OPEN_CURLY_BRACES expr '}' { $$ = Variable[$2]; } | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}' - { $$ = Expr_ArrayDimFetch[var: Variable[$2], dim: $4]; } + { $$ = Expr_ArrayDimFetch[Variable[$2], $4]; } | T_CURLY_OPEN variable '}' { $$ = $2; } ; diff --git a/lib/PHPParser/Node/Expr/Array.php b/lib/PHPParser/Node/Expr/Array.php index 8c281809..a3aba4ac 100644 --- a/lib/PHPParser/Node/Expr/Array.php +++ b/lib/PHPParser/Node/Expr/Array.php @@ -5,4 +5,19 @@ */ class PHPParser_Node_Expr_Array extends PHPParser_Node_Expr { + /** + * Constructs an array node. + * + * @param array $items Items of the array + * @param int $line Line + * @param null|string $docComment Nearest doc comment + */ + public function __construct(array $items = array(), $line = -1, $docComment = null) { + parent::__construct( + array( + 'items' => $items + ), + $line, $docComment + ); + } } \ No newline at end of file diff --git a/lib/PHPParser/Node/Expr/ArrayCast.php b/lib/PHPParser/Node/Expr/ArrayCast.php index 21bf78f9..2b0690e0 100644 --- a/lib/PHPParser/Node/Expr/ArrayCast.php +++ b/lib/PHPParser/Node/Expr/ArrayCast.php @@ -5,4 +5,19 @@ */ class PHPParser_Node_Expr_ArrayCast extends PHPParser_Node_Expr { + /** + * Constructs an array cast node. + * + * @param PHPParser_Node_Expr $expr Expression + * @param int $line Line + * @param null|string $docComment Nearest doc comment + */ + public function __construct(PHPParser_Node_Expr $expr, $line = -1, $docComment = null) { + parent::__construct( + array( + 'expr' => $expr + ), + $line, $docComment + ); + } } \ No newline at end of file diff --git a/lib/PHPParser/Node/Expr/ArrayDimFetch.php b/lib/PHPParser/Node/Expr/ArrayDimFetch.php index 01fcbbfe..0c957be9 100644 --- a/lib/PHPParser/Node/Expr/ArrayDimFetch.php +++ b/lib/PHPParser/Node/Expr/ArrayDimFetch.php @@ -1,9 +1,26 @@ $var, + 'dim' => $dim + ), + $line, $docComment + ); + } } \ No newline at end of file diff --git a/lib/PHPParser/Node/Expr/ArrayItem.php b/lib/PHPParser/Node/Expr/ArrayItem.php index 4aeab488..70c9d793 100644 --- a/lib/PHPParser/Node/Expr/ArrayItem.php +++ b/lib/PHPParser/Node/Expr/ArrayItem.php @@ -1,10 +1,29 @@ $key, + 'value' => $value, + 'byRef' => $byRef + ), + $line, $docComment + ); + } } \ No newline at end of file diff --git a/lib/PHPParser/Node/Variable.php b/lib/PHPParser/Node/Variable.php index e463a3e1..ee9fdae7 100644 --- a/lib/PHPParser/Node/Variable.php +++ b/lib/PHPParser/Node/Variable.php @@ -1,16 +1,16 @@ yyval = new PHPParser_Node_Expr_ArrayCast(array('expr' => $this->yyastk[$this->yysp-(2-2)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayCast($this->yyastk[$this->yysp-(2-2)], $line, $docComment); } private function yyn224($line, $docComment) { @@ -1903,7 +1903,7 @@ class PHPParser_Parser } private function yyn230($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_Array(array('items' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_Array($this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn231($line, $docComment) { @@ -2017,11 +2017,11 @@ class PHPParser_Parser } private function yyn255($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn256($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn257($line, $docComment) { @@ -2121,7 +2121,7 @@ class PHPParser_Parser } private function yyn281($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_Array(array('items' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_Array($this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn282($line, $docComment) { @@ -2177,11 +2177,11 @@ class PHPParser_Parser } private function yyn295($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayItem(array('key' => $this->yyastk[$this->yysp-(3-1)], 'value' => $this->yyastk[$this->yysp-(3-3)], 'byRef' => false), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayItem($this->yyastk[$this->yysp-(3-1)], $this->yyastk[$this->yysp-(3-3)], false, $line, $docComment); } private function yyn296($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $this->yyastk[$this->yysp-(1-1)], 'byRef' => false), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayItem(null, $this->yyastk[$this->yysp-(1-1)], false, $line, $docComment); } private function yyn297($line, $docComment) { @@ -2213,11 +2213,11 @@ class PHPParser_Parser } private function yyn304($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn305($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn306($line, $docComment) { @@ -2261,19 +2261,19 @@ class PHPParser_Parser } private function yyn316($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn317($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn318($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn319($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn320($line, $docComment) { @@ -2341,19 +2341,19 @@ class PHPParser_Parser } private function yyn336($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayItem(array('key' => $this->yyastk[$this->yysp-(3-1)], 'value' => $this->yyastk[$this->yysp-(3-3)], 'byRef' => false), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayItem($this->yyastk[$this->yysp-(3-1)], $this->yyastk[$this->yysp-(3-3)], false, $line, $docComment); } private function yyn337($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $this->yyastk[$this->yysp-(1-1)], 'byRef' => false), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayItem(null, $this->yyastk[$this->yysp-(1-1)], false, $line, $docComment); } private function yyn338($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayItem(array('key' => $this->yyastk[$this->yysp-(4-1)], 'value' => $this->yyastk[$this->yysp-(4-4)], 'byRef' => true), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayItem($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-4)], true, $line, $docComment); } private function yyn339($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $this->yyastk[$this->yysp-(2-2)], 'byRef' => true), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayItem(null, $this->yyastk[$this->yysp-(2-2)], true, $line, $docComment); } private function yyn340($line, $docComment) { @@ -2377,7 +2377,7 @@ class PHPParser_Parser } private function yyn345($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(4-1)], 1), $line, $docComment), 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(4-1)], 1), $line, $docComment), $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn346($line, $docComment) { @@ -2389,7 +2389,7 @@ class PHPParser_Parser } private function yyn348($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable($this->yyastk[$this->yysp-(6-2)], $line, $docComment), 'dim' => $this->yyastk[$this->yysp-(6-4)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(new PHPParser_Node_Variable($this->yyastk[$this->yysp-(6-2)], $line, $docComment), $this->yyastk[$this->yysp-(6-4)], $line, $docComment); } private function yyn349($line, $docComment) { diff --git a/lib/PHPParser/ParserDebug.php b/lib/PHPParser/ParserDebug.php index cb16b2ae..60e36c0f 100644 --- a/lib/PHPParser/ParserDebug.php +++ b/lib/PHPParser/ParserDebug.php @@ -2272,7 +2272,7 @@ class PHPParser_ParserDebug } private function yyn223($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayCast(array('expr' => $this->yyastk[$this->yysp-(2-2)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayCast($this->yyastk[$this->yysp-(2-2)], $line, $docComment); } private function yyn224($line, $docComment) { @@ -2300,7 +2300,7 @@ class PHPParser_ParserDebug } private function yyn230($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_Array(array('items' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_Array($this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn231($line, $docComment) { @@ -2414,11 +2414,11 @@ class PHPParser_ParserDebug } private function yyn255($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn256($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn257($line, $docComment) { @@ -2518,7 +2518,7 @@ class PHPParser_ParserDebug } private function yyn281($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_Array(array('items' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_Array($this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn282($line, $docComment) { @@ -2574,11 +2574,11 @@ class PHPParser_ParserDebug } private function yyn295($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayItem(array('key' => $this->yyastk[$this->yysp-(3-1)], 'value' => $this->yyastk[$this->yysp-(3-3)], 'byRef' => false), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayItem($this->yyastk[$this->yysp-(3-1)], $this->yyastk[$this->yysp-(3-3)], false, $line, $docComment); } private function yyn296($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $this->yyastk[$this->yysp-(1-1)], 'byRef' => false), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayItem(null, $this->yyastk[$this->yysp-(1-1)], false, $line, $docComment); } private function yyn297($line, $docComment) { @@ -2610,11 +2610,11 @@ class PHPParser_ParserDebug } private function yyn304($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn305($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn306($line, $docComment) { @@ -2658,19 +2658,19 @@ class PHPParser_ParserDebug } private function yyn316($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn317($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn318($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn319($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $this->yyastk[$this->yysp-(4-1)], 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn320($line, $docComment) { @@ -2738,19 +2738,19 @@ class PHPParser_ParserDebug } private function yyn336($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayItem(array('key' => $this->yyastk[$this->yysp-(3-1)], 'value' => $this->yyastk[$this->yysp-(3-3)], 'byRef' => false), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayItem($this->yyastk[$this->yysp-(3-1)], $this->yyastk[$this->yysp-(3-3)], false, $line, $docComment); } private function yyn337($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $this->yyastk[$this->yysp-(1-1)], 'byRef' => false), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayItem(null, $this->yyastk[$this->yysp-(1-1)], false, $line, $docComment); } private function yyn338($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayItem(array('key' => $this->yyastk[$this->yysp-(4-1)], 'value' => $this->yyastk[$this->yysp-(4-4)], 'byRef' => true), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayItem($this->yyastk[$this->yysp-(4-1)], $this->yyastk[$this->yysp-(4-4)], true, $line, $docComment); } private function yyn339($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $this->yyastk[$this->yysp-(2-2)], 'byRef' => true), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayItem(null, $this->yyastk[$this->yysp-(2-2)], true, $line, $docComment); } private function yyn340($line, $docComment) { @@ -2774,7 +2774,7 @@ class PHPParser_ParserDebug } private function yyn345($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(4-1)], 1), $line, $docComment), 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(4-1)], 1), $line, $docComment), $this->yyastk[$this->yysp-(4-3)], $line, $docComment); } private function yyn346($line, $docComment) { @@ -2786,7 +2786,7 @@ class PHPParser_ParserDebug } private function yyn348($line, $docComment) { - $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable($this->yyastk[$this->yysp-(6-2)], $line, $docComment), 'dim' => $this->yyastk[$this->yysp-(6-4)]), $line, $docComment); + $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(new PHPParser_Node_Variable($this->yyastk[$this->yysp-(6-2)], $line, $docComment), $this->yyastk[$this->yysp-(6-4)], $line, $docComment); } private function yyn349($line, $docComment) { diff --git a/lib/PHPParser/PrettyPrinter/Zend.php b/lib/PHPParser/PrettyPrinter/Zend.php index d3beb787..d5092cf6 100644 --- a/lib/PHPParser/PrettyPrinter/Zend.php +++ b/lib/PHPParser/PrettyPrinter/Zend.php @@ -10,10 +10,10 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract } public function pVariable(PHPParser_Node_Variable $node) { - if ($node->name instanceof PHPParser_Node_Expr) { - return '${' . $this->p($node->name) . '}'; - } elseif ($node->name instanceof PHPParser_Node_Variable) { + if ($node->name instanceof PHPParser_Node_Variable) { return '$' . $this->p($node->name); + } elseif ($node->name instanceof PHPParser_Node_Expr) { + return '${' . $this->p($node->name) . '}'; } else { return '$' . $node->name; } @@ -619,7 +619,7 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract // Helpers public function pObjectProperty($node) { - if ($node instanceof PHPParser_Node_Variable || $node instanceof PHPParser_Node_Expr) { + if ($node instanceof PHPParser_Node_Expr) { return '{' . $this->p($node) . '}'; } else { return $node; diff --git a/test/PHPParser/Tests/NodeDumperTest.php b/test/PHPParser/Tests/NodeDumperTest.php index 4a4353c0..a6e964f5 100644 --- a/test/PHPParser/Tests/NodeDumperTest.php +++ b/test/PHPParser/Tests/NodeDumperTest.php @@ -37,14 +37,16 @@ class PHPParser_Tests_NodeDumperTest extends PHPUnit_Framework_TestCase )' ), array( - new PHPParser_Node_Expr_Array(array('items' => array( - new PHPParser_Node_Expr_ArrayItem(array('key' => 'Foo', 'value' => 'Bar', 'byRef' => false)) - ))), + new PHPParser_Node_Expr_Array(array( + new PHPParser_Node_Expr_ArrayItem(null, new PHPParser_Node_Scalar_String('Foo')) + )), 'Expr_Array( items: array( 0: Expr_ArrayItem( - key: Foo - value: Bar + key: null + value: Scalar_String( + value: Foo + ) byRef: false ) )