Skip to content

Parse partial function application placeholders and invoking new without parentheses in php8 - #39

Merged
TomasVotruba merged 1 commit into
mainfrom
php8-partial-application-new-invoke
Nov 24, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
php8-partial-application-new-invoke

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Two PHP syntax forms were syntax errors in php8:

  • Partial function application - array_map(trim(?), $items), f($x, ?, y: ?, ...). A placeholder is an ast.Argument without Expr: ? sets the new PlaceholderTkn (with Name/ColonTkn for y: ?), a bare ... sets VariadicTkn, the same shape a first-class callable f(...) already had. The dedicated '(' T_ELLIPSIS ')' rule is gone, since a bare ... is now an argument. Printer, dumper and formatter handle the new token.
  • Invoking a new without parentheses (PHP 8.4) - new Invokable()(). new_dereferenceable joins callable_expr, as in php-src. ->, ?->, :: and [ already worked.

Grammar conflicts stay at the baseline 3 shift/reduce, 7 reduce/reduce.

The legacy curly offset $value{0} is left out on purpose: it is a syntax error since PHP 8.0 (nikic/PHP-Parser rejects it too), and adding it to php8 makes { conflict with property hooks ($x = default { get; }).

…out parentheses in php8

f(?, name: ?, ...) and new Foo()() were syntax errors.

A placeholder is an Argument without Expr: '?' sets the new
PlaceholderTkn, a bare '...' sets VariadicTkn, as a first-class
callable already did. new_dereferenceable joins callable_expr, as in
php-src, so a new with an argument list can be invoked directly.
@TomasVotruba
TomasVotruba merged commit 5980686 into main Nov 24, 2026
5 checks passed
@TomasVotruba
TomasVotruba deleted the php8-partial-application-new-invoke branch November 24, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant