Skip to content
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

Double arrow tokenized as T_STRING when placed after non-arrow function "fn" keyword #2865

Closed
jrfnl opened this issue Feb 11, 2020 · 3 comments
Milestone

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Feb 11, 2020

Given the below code sample, PHP itself tokenizes the => as T_DOUBLE_ARROW, however, since PHPCS 3.5.4, PHPCS tokenizes it as T_STRING.

I haven't traced back yet which commit introduced this, nor figured out yet where to apply the fix.

class Foo {
    public $fn = 'key';

    public function bar() {
        return [
            $this->fn => 'value',
        ];
    }
}

https://3v4l.org/OXelC

Related to #2523

@gsherwood
Copy link
Member

This issue is caused by this change: 0e4fe74

@gsherwood gsherwood changed the title Tokenizer bug: double arrow tokenized as T_STRING Double arrow tokenized as T_STRING when placed after function named "fn" Mar 9, 2020
gsherwood added a commit that referenced this issue Mar 9, 2020
gsherwood added a commit that referenced this issue Mar 9, 2020
@gsherwood
Copy link
Member

The previous change also included the changing of the function name token into a string, which wasn't required for arrow functions, and actually caused a problem given it assumed the next token as a name. Even though the function being called is not actually an arrow function, that decision doesn't happen until processAdditional(), so it looks like one on the first pass.

This is fixed now. Thanks for reporting it.

@jrfnl
Copy link
Contributor Author

jrfnl commented Mar 9, 2020

@gsherwood Thanks for fixing this!

@jrfnl jrfnl changed the title Double arrow tokenized as T_STRING when placed after function named "fn" Double arrow tokenized as T_STRING when placed after non-arrow function "fn" keyword Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants