Closed
Description
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:
- Create a file called
test.php
with the code sample above... - Run
phpcs --standard=PSR12 test.php
- 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
Activity
jakubkosinski99 commentedon Jun 13, 2022
I noticed that too. Nothing can be done
Arthur-Sk commentedon Jun 13, 2022
Same.
As a temporary workaround.
dragosprotung commentedon Jun 13, 2022
This actually is a problem for more function names:
jrfnl commentedon Jun 13, 2022
Thank you all for reporting this. PR #3610 should fix it. Testing appreciated!
Changelog for #3609 (ref #3610)
[-]Method with name `empty` is always reported as error[/-][+]Methods/constants with name empty/isset/unset are always reported as error[/+]Updated changelog message for #3609
3.7.0
methods namedempty
are failing Squiz.Functions.FunctionDeclaration.Found #3613empty
,isset
,unset
as method names #3614