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

PHP 8.3 - Typed class constants support #3927

Closed
3 tasks done
jnoordsij opened this issue Nov 23, 2023 · 6 comments · Fixed by PHPCSStandards/PHP_CodeSniffer#332
Closed
3 tasks done

PHP 8.3 - Typed class constants support #3927

jnoordsij opened this issue Nov 23, 2023 · 6 comments · Fixed by PHPCSStandards/PHP_CodeSniffer#332

Comments

@jnoordsij
Copy link

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:

  • I have searched the issue list and am not opening a duplicate issue.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the master branch of PHP_CodeSniffer.
@MaxiCom
Copy link

MaxiCom commented Dec 2, 2023

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

@matmper
Copy link

matmper commented Dec 4, 2023

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

@guelosuperstart
Copy link

guelosuperstart commented Dec 12, 2023

Hello, same problem

public const string VALUE = 'value';

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

@PatNowak
Copy link

Any news on that?

@ldebrouwer
Copy link

@PatNowak Please take a moment to read; #3932

@jrfnl
Copy link
Contributor

jrfnl commented Feb 16, 2024

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).

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