feat: accept declare(strict_types=1) and declare directives#459
Open
chadmandoo wants to merge 2 commits into
Open
feat: accept declare(strict_types=1) and declare directives#459chadmandoo wants to merge 2 commits into
chadmandoo wants to merge 2 commits into
Conversation
The `declare` keyword was unrecognized, so `declare(strict_types=1);` — the
first line of most modern PHP files — failed to parse ("Invalid assignment
target"), which blocks compiling essentially any strict-typed codebase.
Lex `declare` as a new token and parse `declare(name=value, ...)` in both the
statement form (`declare(strict_types=1);`) and the block form
(`declare(ticks=1) { ... }`). elephc compiles an always-strict subset, so the
directives are parsed for syntactic validity and discarded: the statement form
lowers to an empty `Synthetic` block (a no-op) and the block form to a
`Synthetic` wrapper around its body. Reusing the existing `Synthetic` node means
no analysis or lowering pass needs to change.
Adds lexer, parser, codegen, and error tests, plus a docs section in
docs/php/control-structures.md.
(cherry picked from commit 88e78ca)
(cherry picked from commit f256454)
Member
|
This will be discussed in the next core team meeting. It touches an important area about static / dynamic behaviour |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Accepts
declare(strict_types=1);(anddeclare(...)directives generally) as a top-of-file statement instead of erroring. Every strict-typed PHP file opens with it, so this unblocks compiling any codebase that usesdeclare(strict_types=1).How
Parses the
declare(directive=value)form as a directive statement rather than treatingdirective=valueas an assignment expression (which produced "Invalid assignment target").strict_typesis accepted and does not alter runtime behavior in the compiled output (the compiler is already strict), so byte-parity with PHP is preserved.Verification
Byte-parity vs PHP 8.5 for files opening with
declare(strict_types=1);+ a regression test.