From d63cd79b2031607ca8e4e2fba4d4b276fb6733de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Sat, 20 Aug 2022 14:51:02 +0200 Subject: [PATCH] Add the class constant rule --- wordpress-coding-standards/php.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wordpress-coding-standards/php.md b/wordpress-coding-standards/php.md index 1e8af5e..b40b6df 100644 --- a/wordpress-coding-standards/php.md +++ b/wordpress-coding-standards/php.md @@ -494,6 +494,18 @@ For those, adding `callable`, class and interface name based parameter type decl Using the `array` keyword in type declarations is **strongly discouraged** for now, as most often, it would be better to use `iterable` to allow for more flexibility in the implementation and that keyword is not yet available for use in WordPress Core until the minimum requirements are raised to PHP 7.1. +### The ::class constant + +When using the `::class` constant for class name resolution you should add no space between the `::class` and the preceding class name it applies to. There should be no space between the double colon and the `class` keyword, and the `class` keyword should be in lowercase. + +```php +// Correct. +add_action( 'action_name', array( My_Class::class, 'method_name' ) ); + +// Incorrect. +add_action( 'action_name', array( My_Class :: CLASS, 'method_name' ) ); +``` + ## Declare Statements, Namespace, and Import Statements ### Namespace declarations