microsoft / microsoft/tolerant-php-parser
Idea: Start converting older tokenization to php 8.0 T_NAME_QUALIFIED/T_NAME_RELATIVE/T_NAME_FULLY_QUALIFIED
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 894
- Forks
- 85
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 3
Description
In a new major/0.(x+1) release
On a best effort basis, convert groups of names/keywords/reserved words separated by \ without whitespace to T_NAME_QUALIFIED/T_NAME_RELATIVE/T_NAME_FULLY_QUALIFIED in php < 8.0, do nothing in 8.0+
- Currently, as a workaround, we do the opposite and split those up, but this makes less sense as php 8.0+ adoption grows (for analysis and for the runtime used for this library)
Related to #362
For parseQualifiedName, we might want to either (1) start treating whitespace as special or (2) start actually supporting T_NAME_QUALIFIED in a subsequent major release in the far future when support for < 8.0 is dropped
- i.e. start forbidding the rarely used
a \ bto prepare for that php 8.0 incompatibility
The motivation to do that is to support the way edge cases such as echo\foo would be parsed in 8.0 in more cases (i.e. not echo \foo) after https://wiki.php.net/rfc/namespaced_names_as_token
php > echo PHP_VERSION_ID;
80017
php > new a \ b();
Parse error: syntax error, unexpected token "\" in php shell code on line 1
php > new a\b();
Warning: Uncaught Error: Class "a\b" not found in php shell code:1
Stack trace:
#0 {main}
thrown in php shell code on line 1
php > echo\foo();
Warning: Uncaught Error: Call to undefined function echo\foo() in php shell code:1
Stack trace:
#0 {main}
thrown in php shell code on line 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the parseQualifiedName entry point and the tokenization behavior described for PHP versions before and after 8.0. Compare how names separated by backslashes are currently split with the T_NAME_* tokens, then resolve whether whitespace handling or later support for T_NAME_QUALIFIED is intended. Done means the release scope and compatible behavior are defined, with corresponding parser coverage identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100