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

classes that specify visibility on class constants can't be parsed #224

Open
pbiron opened this issue Aug 14, 2020 · 1 comment
Open

classes that specify visibility on class constants can't be parsed #224

pbiron opened this issue Aug 14, 2020 · 1 comment

Comments

@pbiron
Copy link

pbiron commented Aug 14, 2020

For example,

class My_Class {
    public const C1    = 'value';
    protected const C2 = 'another value';
    ...
}

Trying the parse the above results in an error like:

Parse Error: Syntax error, unexpected T_CONST, expecting T_FUNCTION on line xyz

and the entire class is not imported.

Visibility for class constants wasn't added to PHP until 7.1. Of course, as of today (2020-08-14) nothing in core specifies visibility on class constants since the minimum PHP is still 5.6. And current WPCS states:

Visibility for class constants can not be used in WordPress Core until the minimum PHP version has been raised to PHP 7.1 (and won’t be enforced until that time).

It is hopeful (likely?) that WP 5.6 will bump the minimum PHP to 7.1. So, the need to parse such classes will be coming sooner rather than later.

As best I can tell, the error is generated by nikic/php-parser, which is a transitive dependency of phpdocumentor/reflection. The latest version of nikic/php-parser fully supports PHP 7.1+, so I think the solution is simply to update the composer dependencies of this plugin, but things will need to be tested thoroughly after those dependencies are updated.

@pbiron
Copy link
Author

pbiron commented Aug 17, 2020

Here's the trac ticket to bump PHP to 7.1: https://core.trac.wordpress.org/ticket/51043

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

No branches or pull requests

1 participant