Skip to content

Fix bug #77966: Cannot alias a method named "namespace" #5668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Jun 5, 2020

The basic problem is that the identifier is no longer the lookahead token in this case, which means we have to support the whole machinery for going back more than one token. This means we should remember the identifier on the parser stack and modify the on_event API to distinguish the token the feedback applies to.

@marcioAlmada
Copy link
Contributor

Oh boy. Are there more special cases like that? That one didn't come up during the RFC.

@nikic
Copy link
Member Author

nikic commented Jun 5, 2020

@marcioAlmada This is the only one I'm aware of right now, but this will also be needed for named parameters (which is why I bothered to implement it now).

@php-pulls php-pulls closed this in b03cafd Jun 8, 2020
TysonAndre added a commit to TysonAndre/php-src that referenced this pull request Jan 18, 2021
Related to phpGH-5668
Also affects php 8.0 but this changes the
datastructures in public header files.
(binary ABI change)
PHP 7.4 wouldn't even parse a class with the below example.

1. Fix parsing semi-reserved tokens such as `namespace`
   with an offset that's larger than 2**32
2. Fix parsing some tokens when their length is larger than 2**32

Offset is relative to yy_start(the start of the file?)

Low priority because 4GB php files are extremely rare

```
php > ini_set('memory_limit', '12G');
php > eval(str_repeat(' ' , 2**32) . 'class MyClass{ public static function namespace() {}}');
php > MyClass::namespace();

Warning: Uncaught Error: Call to undefined method MyClass::namespace() in php shell code:1
Stack trace:
  thrown in php shell code on line 1
php > var_export((new ReflectionClass('MyClass'))->getMethods());
array (
  0 =>
  ReflectionMethod::__set_state(array(
     'name' => '         ',
     'class' => 'MyClass',
  )),
)
```
TysonAndre added a commit to TysonAndre/php-src that referenced this pull request Jan 18, 2021
Related to phpGH-5668
Also affects php 8.0 but this changes the
datastructures in public header files.
(binary ABI change)
PHP 7.4 wouldn't even parse a class with the below example.

1. Fix parsing semi-reserved tokens such as `namespace`
   with an offset that's larger than 2**32
2. Fix parsing some tokens when their length is larger than 2**32

Offset is relative to yy_start(the start of the file?)

Low priority because 4GB php files are extremely rare

```
php > ini_set('memory_limit', '12G');
php > eval(str_repeat(' ' , 2**32) . 'class MyClass{ public static function namespace() {}}');
php > MyClass::namespace();

Warning: Uncaught Error: Call to undefined method MyClass::namespace() in php shell code:1
Stack trace:
  thrown in php shell code on line 1
php > var_export((new ReflectionClass('MyClass'))->getMethods());
array (
  0 =>
  ReflectionMethod::__set_state(array(
     'name' => '         ',
     'class' => 'MyClass',
  )),
)
```
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.

2 participants