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

Class constants trigger "const" keyword sniff #129

Closed
chrisbliss18 opened this issue Jul 25, 2016 · 1 comment
Closed

Class constants trigger "const" keyword sniff #129

chrisbliss18 opened this issue Jul 25, 2016 · 1 comment
Labels
Milestone

Comments

@chrisbliss18
Copy link

chrisbliss18 commented Jul 25, 2016

Class constants are supported in PHP 5+. Using "const" outside of a class as an alternative to using "define" requires PHP 5.3+. However, all uses of "const" are treated as requiring PHP 5.3.

I had a look at the keyword sniff, and I'm not sure what the best way would be to detect the different uses of this keyword. Perhaps a new sniff would have to be created to handle the different uses.

The following is a class constant, which is compatible with PHP 5+.

<?php
class MyClass {
    const CONSTANT = 'constant value';
}

The following is a global constant defined using the "const" keyword, which is compatible with PHP 5.3+.

<?php
const CONSTANT = 'Hello World';
@jrfnl
Copy link
Member

jrfnl commented Jul 25, 2016

Sounds like a perfect example for using the PHP_CodeSniffer_Standards_AbstractScopeSniff class as a base and applying different tests to inside and outside (class) scope.

jrfnl added a commit to jrfnl/PHPCompatibility that referenced this issue Aug 6, 2016
Fixes PHPCompatibility#129.

Includes unit tests.
Also documents the `__halt_compiler()` unit test code.
@wimg wimg closed this as completed in #147 Aug 7, 2016
@jrfnl jrfnl added this to the 7.0.3 milestone Apr 30, 2017
@jrfnl jrfnl added the bug label Mar 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants