Skip to content

Warning when static method name is 'default' #1239

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
chriskicker opened this issue Dec 13, 2016 · 3 comments
Closed

Warning when static method name is 'default' #1239

chriskicker opened this issue Dec 13, 2016 · 3 comments

Comments

@chriskicker
Copy link

I get WARNING
Possible parse error: non-abstract method defined as abstract
My test method is:

public static function default(): ObjectA
{
    return new self(1);
}

I use squizlabs/php_codesniffer is 2.7.1

@gsherwood
Copy link
Member

The problem is that PHP tokenizes the string default as T_DEFAULT and then PHPCS sees the colon for the return type and tries to match it with T_DEFAULT, as it does in case statements.

The fix is to change T_DEFAULT to T_STRING earlier (it was done on the second pass, now on the first pass) to stop any matching from taking place.

Thanks for the report.

@pawelbaranski
Copy link

@gsherwood since this is a bug in 2.x version, are you planning to update 2.x as well ? I noticed that the update is only on master right now. Thanks for the fast response btw 👍

@gsherwood
Copy link
Member

@pawelbaranski The master branch is the 2.x version. The fix was also merged into the 3.0 branch, so it will be released in both the next 2.x and 3.x versions.

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

3 participants