Skip to content

Commit

Permalink
Merge branch 'nikic:4.x' into 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
johannescoetzee authored Mar 19, 2024
2 parents b978f6e + 4d36e9c commit 33fc47e
Show file tree
Hide file tree
Showing 71 changed files with 1,760 additions and 1,142 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.github export-ignore
/doc export-ignore
/grammar export-ignore
/test export-ignore
/test_old export-ignore
.editorconfig export-ignore
Expand Down
24 changes: 13 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ on:
pull_request:

jobs:
tests_70:
tests_71:
runs-on: "ubuntu-latest"
name: "PHP 7.0 Unit Tests"
name: "PHP 7.1 Unit Tests"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "xdebug"
php-version: "7.0"
php-version: "7.1"
tools: composer:v2
- name: "Install dependencies"
run: |
Expand All @@ -29,21 +29,22 @@ jobs:
strategy:
matrix:
php-version:
- "7.1"
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
ini-file: "development"
tools: composer:v2
- name: "Install dependencies"
run: "composer update --no-progress --prefer-dist ${{ matrix.flags }}"
Expand All @@ -54,28 +55,29 @@ jobs:
name: "PHP 7.3 Code on PHP 8.0 Integration Tests"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.0"
ini-file: "development"
tools: composer:v2
- name: "Install PHP 8 dependencies"
run: "composer update --no-progress --prefer-dist"
- name: "Tests"
run: "test_old/run-php-src.sh 7.3.21"
test_old_80_70:
test_old_80_71:
runs-on: "ubuntu-latest"
name: "PHP 8.1 Code on PHP 7.0 Integration Tests"
name: "PHP 8.1 Code on PHP 7.1 Integration Tests"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "7.0"
php-version: "7.1"
tools: composer:v2
- name: "Install PHP 8 dependencies"
run: "composer update --no-progress --prefer-dist"
Expand Down
74 changes: 74 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,77 @@
Version 4.19.1 (2024-03-17)
---------------------------

### Fixed

* Fixed "Optional parameter before required parameter" deprecation warning introduced in
previous version.

Version 4.19.0 (2024-03-16)
---------------------------

### Changed

* Do not use implicitly nullable parameters, which are deprecated in PHP 8.4.
* Remove support for running on PHP 7.0, which does not support explicitly nullable parameters.

Version 4.18.0 (2023-12-10)
---------------------------

### Added

* Added methods `ParserFactory::createForNewestSupportedVersion()` and
`ParserFactory::createForHostVersion()` for forward-compatibility with PHP-Parser 5.0.

### Fixed

* Fixed missing name resolution of class constant types.
* Fixed class members being dropped if an error is encountered while parsing a later class member
(when error recovery is enabeld).

### Changed

* The `grammar/` directory has been excluded from exported git archives.

Version 4.17.1 (2023-08-13)
---------------------------

### Fixed

* Fixed phpdoc mismatches for `ClassConst::$type` introduced in previous release.

Version 4.17.0 (2023-08-13)
---------------------------

### Added

* [PHP 8.3] Added support for typed class constants.
* [PHP 8.3] Added supprot for dynamic class constant fetch.
* [PHP 8.3] Added support for readonly anonymous classes.

### Fixed

* Fixed missing required parentheses when pretty printing new with an expression class name.
* Fixed missing required parentheses when pretty printing `(CONST)::$x` and similar.

Version 4.16.0 (2023-06-25)
---------------------------

### Added

* Added `Name::getParts()` method for forward-compatibility with PHP-Parser 5.

### Deprecated

* Deprecated direct access to `Name::$parts`, which will be removed in PHP-Parser 5.

Version 4.15.5 (2023-05-19)
---------------------------

### Added

* Added `makePrivate()`, `makeProtected()`, `makePublic()` and `makeReadonly()` methods to
`Builder\Param` to allow the creation of promoted parameters.

Version 4.15.4 (2023-03-05)
---------------------------

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PHP Parser
This is a PHP 5.2 to PHP 8.2 parser written in PHP. Its purpose is to simplify static code analysis and
manipulation.

[**Documentation for version 4.x**][doc_4_x] (stable; for running on PHP >= 7.0; for parsing PHP 5.2 to PHP 8.2).
[**Documentation for version 4.x**][doc_4_x] (stable; for running on PHP >= 7.1; for parsing PHP 5.2 to PHP 8.2).

[Documentation for version 3.x][doc_3_x] (unsupported; for running on PHP >= 5.5; for parsing PHP 5.2 to PHP 7.2).

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"require": {
"php": ">=7.0",
"php": ">=7.1",
"ext-tokenizer": "*"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion doc/0_Introduction.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The parser supports parsing PHP 5.2-8.0, with the following exceptions:

As the parser is based on the tokens returned by `token_get_all` (which is only able to lex the PHP
version it runs on), additionally a wrapper for emulating tokens from newer versions is provided.
This allows to parse PHP 7.4 source code running on PHP 7.0, for example. This emulation is somewhat
This allows to parse PHP 7.4 source code running on PHP 7.1, for example. This emulation is somewhat
hacky and not perfect, but it should work well on any sane code.

What output does it produce?
Expand Down
4 changes: 2 additions & 2 deletions grammar/php5.y
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ static_var:
;

class_statement_list_ex:
class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } }
class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } else { $$ = $1; } }
| /* empty */ { init(); }
;

Expand Down Expand Up @@ -1008,7 +1008,7 @@ array_pair:
| expr { $$ = Expr\ArrayItem[$1, null, false]; }
| expr T_DOUBLE_ARROW ampersand variable { $$ = Expr\ArrayItem[$4, $1, true]; }
| ampersand variable { $$ = Expr\ArrayItem[$2, null, true]; }
| T_ELLIPSIS expr { $$ = Expr\ArrayItem[$2, null, false, attributes(), true]; }
| T_ELLIPSIS expr { $$ = new Expr\ArrayItem($2, null, false, attributes(), true); }
;

encaps_list:
Expand Down
18 changes: 13 additions & 5 deletions grammar/php7.y
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@ non_empty_class_const_list:
;

class_const:
identifier_maybe_reserved '=' expr { $$ = Node\Const_[$1, $3]; }
T_STRING '=' expr
{ $$ = Node\Const_[new Node\Identifier($1, stackAttributes(#1)), $3]; }
| semi_reserved '=' expr
{ $$ = Node\Const_[new Node\Identifier($1, stackAttributes(#1)), $3]; }
;

inner_statement_list_ex:
Expand Down Expand Up @@ -705,7 +708,7 @@ static_var:
;

class_statement_list_ex:
class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } }
class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } else { $$ = $1; } }
| /* empty */ { init(); }
;

Expand All @@ -722,6 +725,9 @@ class_statement:
| optional_attributes method_modifiers T_CONST class_const_list semi
{ $$ = new Stmt\ClassConst($4, $2, attributes(), $1);
$this->checkClassConst($$, #2); }
| optional_attributes method_modifiers T_CONST type_expr class_const_list semi
{ $$ = new Stmt\ClassConst($5, $2, attributes(), $1, $4);
$this->checkClassConst($$, #2); }
| optional_attributes method_modifiers T_FUNCTION optional_ref identifier_maybe_reserved '(' parameter_list ')'
optional_return_type method_body
{ $$ = Stmt\ClassMethod[$5, ['type' => $2, 'byRef' => $4, 'params' => $7, 'returnType' => $9, 'stmts' => $10, 'attrGroups' => $1]];
Expand Down Expand Up @@ -943,8 +949,8 @@ expr:
;

anonymous_class:
optional_attributes T_CLASS ctor_arguments extends_from implements_list '{' class_statement_list '}'
{ $$ = array(Stmt\Class_[null, ['type' => 0, 'extends' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]], $3);
optional_attributes class_entry_type ctor_arguments extends_from implements_list '{' class_statement_list '}'
{ $$ = array(Stmt\Class_[null, ['type' => $2, 'extends' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]], $3);
$this->checkClass($$[0], -1); }
;

Expand Down Expand Up @@ -1040,6 +1046,8 @@ constant:
class_constant:
class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_maybe_reserved
{ $$ = Expr\ClassConstFetch[$1, $3]; }
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '{' expr '}'
{ $$ = Expr\ClassConstFetch[$1, $4]; }
/* We interpret an isolated FOO:: as an unfinished class constant fetch. It could also be
an unfinished static property fetch or unfinished scoped call. */
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM error
Expand Down Expand Up @@ -1194,7 +1202,7 @@ array_pair:
| expr T_DOUBLE_ARROW expr { $$ = Expr\ArrayItem[$3, $1, false]; }
| expr T_DOUBLE_ARROW ampersand variable { $$ = Expr\ArrayItem[$4, $1, true]; }
| expr T_DOUBLE_ARROW list_expr { $$ = Expr\ArrayItem[$3, $1, false]; }
| T_ELLIPSIS expr { $$ = Expr\ArrayItem[$2, null, false, attributes(), true]; }
| T_ELLIPSIS expr { $$ = new Expr\ArrayItem($2, null, false, attributes(), true); }
| /* empty */ { $$ = null; }
;

Expand Down
18 changes: 17 additions & 1 deletion lib/PhpParser/Builder/ClassConst.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ClassConst implements PhpParser\Builder

/** @var Node\AttributeGroup[] */
protected $attributeGroups = [];
/** @var Identifier|Node\Name|Node\ComplexType */
protected $type;

/**
* Creates a class constant builder
Expand Down Expand Up @@ -116,6 +118,19 @@ public function addAttribute($attribute) {
return $this;
}

/**
* Sets the constant type.
*
* @param string|Node\Name|Identifier|Node\ComplexType $type
*
* @return $this
*/
public function setType($type) {
$this->type = BuilderHelpers::normalizeType($type);

return $this;
}

/**
* Returns the built class node.
*
Expand All @@ -126,7 +141,8 @@ public function getNode(): PhpParser\Node {
$this->constants,
$this->flags,
$this->attributes,
$this->attributeGroups
$this->attributeGroups,
$this->type
);
}
}
17 changes: 14 additions & 3 deletions lib/PhpParser/Builder/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function makeVariadic() {
}

/**
* Makes the parameter public.
* Makes the (promoted) parameter public.
*
* @return $this The builder instance (for fluid interface)
*/
Expand All @@ -109,7 +109,7 @@ public function makePublic() {
}

/**
* Makes the parameter protected.
* Makes the (promoted) parameter protected.
*
* @return $this The builder instance (for fluid interface)
*/
Expand All @@ -120,7 +120,7 @@ public function makeProtected() {
}

/**
* Makes the parameter private.
* Makes the (promoted) parameter private.
*
* @return $this The builder instance (for fluid interface)
*/
Expand All @@ -130,6 +130,17 @@ public function makePrivate() {
return $this;
}

/**
* Makes the (promoted) parameter readonly.
*
* @return $this The builder instance (for fluid interface)
*/
public function makeReadonly() {
$this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_READONLY);

return $this;
}

/**
* Adds an attribute group.
*
Expand Down
6 changes: 3 additions & 3 deletions lib/PhpParser/BuilderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,15 @@ public function propertyFetch(Expr $var, $name) : Expr\PropertyFetch {
/**
* Creates a class constant fetch node.
*
* @param string|Name|Expr $class Class name
* @param string|Identifier $name Constant name
* @param string|Name|Expr $class Class name
* @param string|Identifier|Expr $name Constant name
*
* @return Expr\ClassConstFetch
*/
public function classConstFetch($class, $name): Expr\ClassConstFetch {
return new Expr\ClassConstFetch(
BuilderHelpers::normalizeNameOrExpr($class),
BuilderHelpers::normalizeIdentifier($name)
BuilderHelpers::normalizeIdentifierOrExpr($name)
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/ConstExprEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ConstExprEvaluator
*
* @param callable|null $fallbackEvaluator To call if subexpression cannot be evaluated
*/
public function __construct(callable $fallbackEvaluator = null) {
public function __construct(?callable $fallbackEvaluator = null) {
$this->fallbackEvaluator = $fallbackEvaluator ?? function(Expr $expr) {
throw new ConstExprEvaluationException(
"Expression of type {$expr->getType()} cannot be evaluated"
Expand Down
Loading

0 comments on commit 33fc47e

Please sign in to comment.