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

Method with name eval is always reported as error #3607

Closed
Philosoft opened this issue Jun 12, 2022 · 6 comments · Fixed by #3608
Closed

Method with name eval is always reported as error #3607

Philosoft opened this issue Jun 12, 2022 · 6 comments · Fixed by #3608
Milestone

Comments

@Philosoft
Copy link

Describe the bug

PHPCS considers methods with name eval to be incorrect

Code sample

<?php

declare(strict_types=1);

namespace App;

class Foo
{
    public function eval()
    {
        return;
    }
}

Custom ruleset
No custom rules. Just PSR12 standrad

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above
  2. Run phpcs --standard=PSR12 test.php
  3. See error message displayed
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 9 | ERROR | Expected "function abc(...)"; found "function abc(...)"
----------------------------------------------------------------------

If you change method name to basically anything else - eval1, evaluate etc - there is no error

Expected behavior
No complains.

Versions (please complete the following information):

  • OS: Ubuntu 20.04
  • PHP: 7.4.3
  • PHPCS: master (5e27199)
  • Standard: PSR12

Same thing happens with PHP 8.1.6

@jrfnl
Copy link
Contributor

jrfnl commented Jun 12, 2022

Thanks for reporting this @Philosoft !

I've confirmed the bug.

The eval keyword in a function declaration tokenized (correctly) as a T_STRING in PHPCS 3.6.2.
The change in #3484 to improve context sensitive keyword tokenization did not account for the eval keyword and broke this.

PR #3608 should fix this. Testing appreciated.

@gsherwood gsherwood added this to the 3.7.0 milestone Jun 13, 2022
@gsherwood
Copy link
Member

Thanks for finding and reporting this before it was released

@Mitiaj
Copy link

Mitiaj commented Jun 13, 2022

Same issue with methods named isSet($args) and empty($args)

@gsherwood
Copy link
Member

@Mitiaj Those were also fixed in the same PR created by @jrfnl

@Saeufer
Copy link

Saeufer commented Jun 16, 2022

@Mitiaj Those were also fixed in the same PR created by @jrfnl

Unfortunately still same issue with "unset".

<?php

declare(strict_types=1);

namespace App;

class Foo
{
    public function unset()
    {
        return;
    }
}
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 9 | ERROR | Expected "function abc(...)"; found "function abc(...)"
----------------------------------------------------------------------

@jrfnl
Copy link
Contributor

jrfnl commented Jun 16, 2022

@Saeufer Please try master as that was fixed as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants