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 named 'empty' results in 'Unexpected token: empty' #556

Open
lucasvanlierop opened this issue Mar 14, 2018 · 4 comments
Open

method named 'empty' results in 'Unexpected token: empty' #556

lucasvanlierop opened this issue Mar 14, 2018 · 4 comments

Comments

@lucasvanlierop
Copy link

This code

<?php
declare(strict_types = 1);

final class Test
{
    public static function empty()
    {
    }
}

Results in:
Unexpected token: empty, line: 6, col: 28, file: Test.php.

@sanmai
Copy link

sanmai commented Mar 15, 2018

Seeing same error on a non-static method. Seems like related to #389.

$ php vendor/bin/phpmd --version
PHPMD 2.6.0

@baer95
Copy link

baer95 commented Feb 26, 2019

Just had this issue too - also appears to happen with the reserved words NEW, EMPTY, and DEFAULT that are explicitly allowed as method names or in my case constants: http://php.net/manual/en/reserved.keywords.php.

PHP 7.2
PHPMD 6.2.0

@tvbeek
Copy link
Member

tvbeek commented Sep 24, 2019

It depends on pdepend/pdepend#383

@kylekatarnls
Copy link
Member

Sadly pdepend/pdepend#383 will not be enough, I tested with dev-php-7.1-compatibility and the unexpected token is still there. It should be handled afterward.

In fact, the token_get_all itself produces this misleading result:
https://3v4l.org/rk6uH

After function, the tokenizer should give us a T_STRING, but it actually gives a T_EMPTY. That means the PHP parser handle it while it should be the responsibility of the tokenizer (lexer) if well enclosed.

@ravage84 ravage84 added this to the 2.x (unspecific) milestone May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants