tolerant-php-parser icon indicating copy to clipboard operation
tolerant-php-parser copied to clipboard

Idea: Start converting older tokenization to php 8.0 T_NAME_QUALIFIED/T_NAME_RELATIVE/T_NAME_FULLY_QUALIFIED

Open TysonAndre opened this issue 3 years ago • 0 comments
trafficstars

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 \ b to 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

TysonAndre avatar Aug 26 '22 00:08 TysonAndre