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

Methods/constants with name empty/isset/unset are always reported as error #3609

Closed
dlakomski opened this issue Jun 13, 2022 · 4 comments · Fixed by #3610
Closed

Methods/constants with name empty/isset/unset are always reported as error #3609

dlakomski opened this issue Jun 13, 2022 · 4 comments · Fixed by #3610
Milestone

Comments

@dlakomski
Copy link

dlakomski commented Jun 13, 2022

Describe the bug
PHPCS considers methods with name empty to be incorrect

Code sample

<?php

declare(strict_types=1);

namespace App;

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

Custom ruleset
No custom rules. Just PSR12 standard

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 - empty1, createEmpty etc - there is no error

Expected behavior
No complains.

Versions (please complete the following information):

  • OS: Ubuntu 20.04
  • PHP: 8.1.6
  • PHPCS: 3.7.0
  • Standard: PSR12
@jakubkosinski99
Copy link

I noticed that too. Nothing can be done

@Arthur-Sk
Copy link

Arthur-Sk commented Jun 13, 2022

Same.

// @codingStandardsIgnoreStart
public function empty() 
{
  // @codingStandardsIgnoreEnd

As a temporary workaround.

@dragosprotung
Copy link

dragosprotung commented Jun 13, 2022

This actually is a problem for more function names:

<?php

declare(strict_types=1);

final class Test
{
    public function unset()
    {
        return;
    }

    public function empty()
    {
        return;
    }

    public function isset()
    {
        return;
    }
}
--------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
--------------------------------------------------------------------------
  7 | ERROR | Expected "function abc(...)"; found "function abc(...)"
    |       | (Squiz.Functions.FunctionDeclaration.Found)
 12 | ERROR | Expected "function abc(...)"; found "function abc(...)"
    |       | (Squiz.Functions.FunctionDeclaration.Found)
 17 | ERROR | Expected "function abc(...)"; found "function abc(...)"
    |       | (Squiz.Functions.FunctionDeclaration.Found)
--------------------------------------------------------------------------

@jrfnl
Copy link
Contributor

jrfnl commented Jun 13, 2022

Thank you all for reporting this. PR #3610 should fix it. Testing appreciated!

@gsherwood gsherwood added this to the 3.7.1 milestone Jun 13, 2022
gsherwood added a commit that referenced this issue Jun 13, 2022
@gsherwood gsherwood changed the title Method with name empty is always reported as error Methods/constants with name empty/isset/unset are always reported as error Jun 13, 2022
gsherwood added a commit that referenced this issue Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants