squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.68k stars 1.48k forks source link

PHP 8.3 - Typed class constants support #3927

Closed jnoordsij closed 9 months ago

jnoordsij commented 1 year ago

Describe the bug

PHP 8.3 allows defining a type for class constants (see https://php.watch/versions/8.3/typed-constants) to enforce compatibility with overrides and have better static analysis support.

When using this with current stable phpcs, this triggers an error message like:

Class constants must be uppercase; expected STRING but found string

Code sample

class Test {
    const string TEST_CONSTANT = 'test';
}

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
  <description>If you are using a custom ruleset, please enter it here.</description>
</ruleset>

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. See error message displayed
    Class constants must be uppercase; expected STRING but found string

Expected behavior

No error.

Versions (please complete the following information)

Operating System any
PHP version 8.3
PHP_CodeSniffer version latest
Standard any?
Install type composer

Please confirm:

MaxiCom commented 11 months ago

I encountered the same bug today, looking forward a fix! :wave:

matmper commented 11 months ago

Same problem, for now I'm ignoring my Enum folder.

guelosuperstart commented 11 months ago

Hello, same problem

public const string VALUE = 'value';

phpcs: Class constants must be uppercase; expected STRING but found string

PatNowak commented 11 months ago

Any news on that?

ldebrouwer commented 11 months ago

@PatNowak Please take a moment to read; https://github.com/squizlabs/PHP_CodeSniffer/issues/3932

jrfnl commented 9 months ago

FYI: a fix for this issue is included in today's PHP_CodeSniffer 3.9.0 release.

As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo).