diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index d46eb79..e6d5719 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -6,6 +6,11 @@ Upgrading from PHP-Parser 3.x to 4.0 PHP-Parser now requires PHP 5.6 or newer to run. It is however still possible to *parse* PHP 5.2-5.5 source code, while running on a newer version. +### Changes to the node structure + +* Expression statements (`expr;`) are now represented using a `Stmt\Expression` node. Previously + these statements were directly represented as their constituent expression. + ### Removed functionality * Removed `type` subnode on `Class`, `ClassMethod` and `Property` nodes. Use `flags` instead. \ No newline at end of file diff --git a/lib/PhpParser/Node/Expr/Closure.php b/lib/PhpParser/Node/Expr/Closure.php index 5d37655..7a33460 100644 --- a/lib/PhpParser/Node/Expr/Closure.php +++ b/lib/PhpParser/Node/Expr/Closure.php @@ -18,7 +18,7 @@ class Closure extends Expr implements FunctionLike public $uses; /** @var null|string|Node\Name|Node\NullableType Return type */ public $returnType; - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** diff --git a/lib/PhpParser/Node/Stmt/Case_.php b/lib/PhpParser/Node/Stmt/Case_.php index 03f892c..63f56b8 100644 --- a/lib/PhpParser/Node/Stmt/Case_.php +++ b/lib/PhpParser/Node/Stmt/Case_.php @@ -8,14 +8,14 @@ class Case_ extends Node\Stmt { /** @var null|Node\Expr $cond Condition (null for default) */ public $cond; - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** * Constructs a case node. * * @param null|Node\Expr $cond Condition (null for default) - * @param Node[] $stmts Statements + * @param Node\Stmt[] $stmts Statements * @param array $attributes Additional attributes */ public function __construct($cond, array $stmts = array(), array $attributes = array()) { diff --git a/lib/PhpParser/Node/Stmt/Catch_.php b/lib/PhpParser/Node/Stmt/Catch_.php index 58337ad..89e79a4 100644 --- a/lib/PhpParser/Node/Stmt/Catch_.php +++ b/lib/PhpParser/Node/Stmt/Catch_.php @@ -10,7 +10,7 @@ class Catch_ extends Node\Stmt public $types; /** @var string Variable for exception */ public $var; - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** @@ -18,7 +18,7 @@ class Catch_ extends Node\Stmt * * @param Node\Name[] $types Types of exceptions to catch * @param string $var Variable for exception - * @param Node[] $stmts Statements + * @param Node\Stmt[] $stmts Statements * @param array $attributes Additional attributes */ public function __construct(array $types, $var, array $stmts = array(), array $attributes = array()) { diff --git a/lib/PhpParser/Node/Stmt/ClassLike.php b/lib/PhpParser/Node/Stmt/ClassLike.php index f905335..e7ab00e 100644 --- a/lib/PhpParser/Node/Stmt/ClassLike.php +++ b/lib/PhpParser/Node/Stmt/ClassLike.php @@ -7,7 +7,7 @@ use PhpParser\Node; abstract class ClassLike extends Node\Stmt { /** @var string|null Name */ public $name; - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** diff --git a/lib/PhpParser/Node/Stmt/ClassMethod.php b/lib/PhpParser/Node/Stmt/ClassMethod.php index cfa9b43..29deae5 100644 --- a/lib/PhpParser/Node/Stmt/ClassMethod.php +++ b/lib/PhpParser/Node/Stmt/ClassMethod.php @@ -17,7 +17,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike public $params; /** @var null|string|Node\Name|Node\NullableType Return type */ public $returnType; - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** diff --git a/lib/PhpParser/Node/Stmt/Declare_.php b/lib/PhpParser/Node/Stmt/Declare_.php index 32739f3..797f547 100644 --- a/lib/PhpParser/Node/Stmt/Declare_.php +++ b/lib/PhpParser/Node/Stmt/Declare_.php @@ -8,14 +8,14 @@ class Declare_ extends Node\Stmt { /** @var DeclareDeclare[] List of declares */ public $declares; - /** @var Node[] Statements */ + /** @var Node\Stmt[]|null Statements */ public $stmts; /** * Constructs a declare node. * * @param DeclareDeclare[] $declares List of declares - * @param Node[]|null $stmts Statements + * @param Node\Stmt[]|null $stmts Statements * @param array $attributes Additional attributes */ public function __construct(array $declares, array $stmts = null, array $attributes = array()) { diff --git a/lib/PhpParser/Node/Stmt/Do_.php b/lib/PhpParser/Node/Stmt/Do_.php index 77b0ff4..94c7e2d 100644 --- a/lib/PhpParser/Node/Stmt/Do_.php +++ b/lib/PhpParser/Node/Stmt/Do_.php @@ -6,7 +6,7 @@ use PhpParser\Node; class Do_ extends Node\Stmt { - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** @var Node\Expr Condition */ public $cond; @@ -14,9 +14,9 @@ class Do_ extends Node\Stmt /** * Constructs a do while node. * - * @param Node\Expr $cond Condition - * @param Node[] $stmts Statements - * @param array $attributes Additional attributes + * @param Node\Expr $cond Condition + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $stmts = array(), array $attributes = array()) { parent::__construct($attributes); diff --git a/lib/PhpParser/Node/Stmt/ElseIf_.php b/lib/PhpParser/Node/Stmt/ElseIf_.php index 608878f..babcbe4 100644 --- a/lib/PhpParser/Node/Stmt/ElseIf_.php +++ b/lib/PhpParser/Node/Stmt/ElseIf_.php @@ -8,15 +8,15 @@ class ElseIf_ extends Node\Stmt { /** @var Node\Expr Condition */ public $cond; - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** * Constructs an elseif node. * - * @param Node\Expr $cond Condition - * @param Node[] $stmts Statements - * @param array $attributes Additional attributes + * @param Node\Expr $cond Condition + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $stmts = array(), array $attributes = array()) { parent::__construct($attributes); diff --git a/lib/PhpParser/Node/Stmt/Else_.php b/lib/PhpParser/Node/Stmt/Else_.php index c91a148..7c840b7 100644 --- a/lib/PhpParser/Node/Stmt/Else_.php +++ b/lib/PhpParser/Node/Stmt/Else_.php @@ -6,14 +6,14 @@ use PhpParser\Node; class Else_ extends Node\Stmt { - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** * Constructs an else node. * - * @param Node[] $stmts Statements - * @param array $attributes Additional attributes + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ public function __construct(array $stmts = array(), array $attributes = array()) { parent::__construct($attributes); diff --git a/lib/PhpParser/Node/Stmt/Finally_.php b/lib/PhpParser/Node/Stmt/Finally_.php index 0e3eabb..0ae25d6 100644 --- a/lib/PhpParser/Node/Stmt/Finally_.php +++ b/lib/PhpParser/Node/Stmt/Finally_.php @@ -6,14 +6,14 @@ use PhpParser\Node; class Finally_ extends Node\Stmt { - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** * Constructs a finally node. * - * @param Node[] $stmts Statements - * @param array $attributes Additional attributes + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ public function __construct(array $stmts = array(), array $attributes = array()) { parent::__construct($attributes); diff --git a/lib/PhpParser/Node/Stmt/For_.php b/lib/PhpParser/Node/Stmt/For_.php index 2ca88a3..1a24586 100644 --- a/lib/PhpParser/Node/Stmt/For_.php +++ b/lib/PhpParser/Node/Stmt/For_.php @@ -12,7 +12,7 @@ class For_ extends Node\Stmt public $cond; /** @var Node\Expr[] Loop expressions */ public $loop; - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** diff --git a/lib/PhpParser/Node/Stmt/Foreach_.php b/lib/PhpParser/Node/Stmt/Foreach_.php index d2c6432..3b1ca9f 100644 --- a/lib/PhpParser/Node/Stmt/Foreach_.php +++ b/lib/PhpParser/Node/Stmt/Foreach_.php @@ -14,7 +14,7 @@ class Foreach_ extends Node\Stmt public $byRef; /** @var Node\Expr Variable to assign value to */ public $valueVar; - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** diff --git a/lib/PhpParser/Node/Stmt/Function_.php b/lib/PhpParser/Node/Stmt/Function_.php index 4c1f48d..d8afb79 100644 --- a/lib/PhpParser/Node/Stmt/Function_.php +++ b/lib/PhpParser/Node/Stmt/Function_.php @@ -15,7 +15,7 @@ class Function_ extends Node\Stmt implements FunctionLike public $params; /** @var null|string|Node\Name|Node\NullableType Return type */ public $returnType; - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** diff --git a/lib/PhpParser/Node/Stmt/If_.php b/lib/PhpParser/Node/Stmt/If_.php index 98bda35..6244b7a 100644 --- a/lib/PhpParser/Node/Stmt/If_.php +++ b/lib/PhpParser/Node/Stmt/If_.php @@ -8,7 +8,7 @@ class If_ extends Node\Stmt { /** @var Node\Expr Condition expression */ public $cond; - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** @var ElseIf_[] Elseif clauses */ public $elseifs; diff --git a/lib/PhpParser/Node/Stmt/Namespace_.php b/lib/PhpParser/Node/Stmt/Namespace_.php index 8b2d48e..e585d72 100644 --- a/lib/PhpParser/Node/Stmt/Namespace_.php +++ b/lib/PhpParser/Node/Stmt/Namespace_.php @@ -8,15 +8,15 @@ class Namespace_ extends Node\Stmt { /** @var null|Node\Name Name */ public $name; - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** * Constructs a namespace node. * - * @param null|Node\Name $name Name - * @param null|Node[] $stmts Statements - * @param array $attributes Additional attributes + * @param null|Node\Name $name Name + * @param null|Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ public function __construct(Node\Name $name = null, $stmts = array(), array $attributes = array()) { parent::__construct($attributes); diff --git a/lib/PhpParser/Node/Stmt/TryCatch.php b/lib/PhpParser/Node/Stmt/TryCatch.php index 0ff36cc..ae2fe57 100644 --- a/lib/PhpParser/Node/Stmt/TryCatch.php +++ b/lib/PhpParser/Node/Stmt/TryCatch.php @@ -6,7 +6,7 @@ use PhpParser\Node; class TryCatch extends Node\Stmt { - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** @var Catch_[] Catches */ public $catches; @@ -16,7 +16,7 @@ class TryCatch extends Node\Stmt /** * Constructs a try catch node. * - * @param Node[] $stmts Statements + * @param Node\Stmt[] $stmts Statements * @param Catch_[] $catches Catches * @param null|Finally_ $finally Optionaly finally node * @param array|null $attributes Additional attributes diff --git a/lib/PhpParser/Node/Stmt/While_.php b/lib/PhpParser/Node/Stmt/While_.php index afad1b2..a36a8cf 100644 --- a/lib/PhpParser/Node/Stmt/While_.php +++ b/lib/PhpParser/Node/Stmt/While_.php @@ -8,15 +8,15 @@ class While_ extends Node\Stmt { /** @var Node\Expr Condition */ public $cond; - /** @var Node[] Statements */ + /** @var Node\Stmt[] Statements */ public $stmts; /** * Constructs a while node. * - * @param Node\Expr $cond Condition - * @param Node[] $stmts Statements - * @param array $attributes Additional attributes + * @param Node\Expr $cond Condition + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $stmts = array(), array $attributes = array()) { parent::__construct($attributes); diff --git a/lib/PhpParser/Parser.php b/lib/PhpParser/Parser.php index fb7dcad..717a24f 100644 --- a/lib/PhpParser/Parser.php +++ b/lib/PhpParser/Parser.php @@ -10,8 +10,8 @@ interface Parser { * @param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults * to ErrorHandler\Throwing. * - * @return Node[]|null Array of statements (or null if the 'throwOnError' option is disabled and the parser was - * unable to recover from an error). + * @return Node\Stmt[]|null Array of statements (or null non-throwing error handler is used and + * the parser was unable to recover from an error). */ public function parse($code, ErrorHandler $errorHandler = null); } diff --git a/lib/PhpParser/ParserAbstract.php b/lib/PhpParser/ParserAbstract.php index fbc53fc..7982851 100644 --- a/lib/PhpParser/ParserAbstract.php +++ b/lib/PhpParser/ParserAbstract.php @@ -157,8 +157,8 @@ abstract class ParserAbstract implements Parser * @param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults * to ErrorHandler\Throwing. * - * @return Node[]|null Array of statements (or null if the 'throwOnError' option is disabled and the parser was - * unable to recover from an error). + * @return Node\Stmt[]|null Array of statements (or null non-throwing error handler is used and + * the parser was unable to recover from an error). */ public function parse($code, ErrorHandler $errorHandler = null) { $this->errorHandler = $errorHandler ?: new ErrorHandler\Throwing; @@ -445,8 +445,8 @@ abstract class ParserAbstract implements Parser /** * Moves statements of semicolon-style namespaces into $ns->stmts and checks various error conditions. * - * @param Node[] $stmts - * @return Node[] + * @param Node\Stmt[] $stmts + * @return Node\Stmt[] */ protected function handleNamespaces(array $stmts) { $hasErrored = false;