Skip to content

Commit

Permalink
Add the class constant rule
Browse files Browse the repository at this point in the history
  • Loading branch information
dingo-d committed Aug 20, 2022
1 parent 7193559 commit d63cd79
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions wordpress-coding-standards/php.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d63cd79

Please sign in to comment.