Skip to content

Add missing PHP 8.5 syntax support#1238

Merged
jorgsowa merged 10 commits into
glayzzle:mainfrom
EverstormDevelopment:feature/php-8-5-support
Apr 2, 2026
Merged

Add missing PHP 8.5 syntax support#1238
jorgsowa merged 10 commits into
glayzzle:mainfrom
EverstormDevelopment:feature/php-8-5-support

Conversation

@EverstormDevelopment
Copy link
Copy Markdown
Contributor

Closes #1237

This PR adds the remaining PHP 8.5 syntax support that was still missing or incomplete in the parser.

Included changes:

  • Add support for PHP 8.5 clone with syntax such as clone($obj, ["name" => $name])
  • Align pipe operator parsing with the final accepted PHP 8.5 syntax by requiring parentheses around arrow functions in pipe chains
  • Support closures in PHP 8.5 attribute constant expressions such as #[A(static function () { return 1; })]

Tests:

  • Add focused regression coverage for clone with
  • Update pipe operator tests and snapshots to reflect the final syntax
  • Add attribute test coverage for closures in constant expressions
  • Verify the Jest test suite passes

Add a snapshot test for PHP 8.5 clone-with syntax by parsing `clone($obj, ["name" => $name, "id" => getId(...)])` with parser version 8.5.

Update the clone snapshot to assert the expected AST shape, including the `Clone` node, property override array entries, the `getId(...)` call, and the variadic placeholder. This documents the new syntax and provides regression coverage for clone expressions with property overrides.
Add parser support for PHP 8.5 clone-with syntax such as `clone($obj, ["name" => $name])`.

Extend clone expression parsing to accept the parenthesized 8.5 form with optional property overrides, preserve the existing clone behavior for older syntax, and expose the override expression on the `Clone` AST node. Update the type definitions accordingly so the new AST shape is represented consistently.
Update the PHP 8.5 pipe operator tests to match the final accepted syntax.

Wrap the valid arrow function step in parentheses and add a regression test asserting that unparenthesized arrow functions in a pipe chain are rejected. Update the pipe snapshots to reflect the new expected AST and error behavior.
Align PHP 8.5 pipe operator parsing with the final accepted RFC behavior.

Reject unparenthesized arrow functions when they are used as a step in a pipe chain, while preserving the existing PHP 8.5 version gate and the current behavior for valid pipe expressions.
…ions

Add snapshot coverage for closures in PHP 8.5 attribute constant expressions.

Parse an attribute argument containing a static anonymous function with parser version 8.5 and update the attribute snapshots to capture the expected AST. This provides regression coverage for the new constant-expression closure syntax inside attributes.
Allow the attribute lexer to tokenize closure bodies used inside PHP 8.5 attribute constant expressions.

Accept the missing closure-body terminals in attribute parsing so static anonymous functions inside attribute arguments can be parsed correctly, while preserving the existing attribute parsing behavior for other expressions.
Adjust the clone AST and snapshot test files to match the repository's Prettier formatting rules.

This resolves the lint failures reported in CI without changing the clone-with behavior.
Regenerate `types.d.ts` so the committed type definitions match the current JSDoc output.

This updates the generated declaration for the `Clone.properties` field and resolves the type-check diff reported in CI.
Copy link
Copy Markdown
Collaborator

@jorgsowa jorgsowa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI fails. If you can please add more test cases with the location, because I'm not sure if location numbers are correct for those features. Otherwise looks good to go. Thanks!

Add location snapshot coverage for the new PHP 8.5 syntax cases introduced in this PR.

Cover `clone with` expressions, pipe chains with parenthesized arrow functions, and closures in attribute constant expressions with `withPositions` and `withSource` enabled. This helps verify that the location metadata for the new syntax is computed correctly.
@EverstormDevelopment
Copy link
Copy Markdown
Contributor Author

EverstormDevelopment commented Apr 1, 2026

Thanks! I added focused location coverage for the new PHP 8.5 syntax cases (clone with, pipe with parenthesized arrow function, and closures in attribute constant expressions) and verified the test suite locally.

The previous CI failure was due to a diff in types.d.ts, even though I had already regenerated it with yarn build-types. I’ve regenerated it again and also verified the output in a Linux Docker container. I can’t see the exact CI diff from the failed run, so for now I’ll wait for the next run and adjust if it still reports a mismatch.

Regenerate `types.d.ts` from a fresh Linux checkout so the committed output matches the CI environment.
@EverstormDevelopment
Copy link
Copy Markdown
Contributor Author

I found the types.d.ts issue.

My earlier Docker check was using the mounted Windows workspace, which turned out not to be a clean reproduction of the GitHub runner. A fresh Linux checkout generates slightly different JSDoc formatting in types.d.ts than my Windows environment did. I regenerated the file from a fresh Linux checkout and pushed the updated output, which should align the generated file with CI.

@jorgsowa jorgsowa merged commit e359d89 into glayzzle:main Apr 2, 2026
3 checks passed
@jorgsowa
Copy link
Copy Markdown
Collaborator

jorgsowa commented Apr 2, 2026

Thanks!

@EverstormDevelopment
Copy link
Copy Markdown
Contributor Author

Hi! Just checking in regarding the next release timeline for the php-parser.

The PHP 8.5 support was merged a while ago, and I’m currently waiting for the next release so I can use it in a personal project. Is there already an approximate plan for when the next release might happen? Just asking so I can plan accordingly.

Thanks!

@jorgsowa
Copy link
Copy Markdown
Collaborator

jorgsowa commented May 3, 2026

I'm sorry, but I cannot give clear answer now. I'm not releasing new versions, I'm only fixing bugs in this project.

@EverstormDevelopment
Copy link
Copy Markdown
Contributor Author

No problem, thanks for the clarification! I appreciate the work you're putting into maintaining the project.

@czosel
Copy link
Copy Markdown
Collaborator

czosel commented May 7, 2026

Hi @EverstormDevelopment, I’ll cut a new release when I’m back from my leave, latest in early June!

@EverstormDevelopment
Copy link
Copy Markdown
Contributor Author

That’s great news, thanks for the update! Looking forward to the release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP 8.5 support is incomplete: clone with syntax, final pipe syntax, and closures in attribute constant expressions

4 participants