Skip to content

Commit

Permalink
Merge pull request #131 from WordPress/feature/various-tweaks
Browse files Browse the repository at this point in the history
Various small tweaks
  • Loading branch information
GaryJones authored Jul 19, 2023
2 parents 2d8390a + 212882f commit 79f8ab4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions wordpress-coding-standards/php.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ $args = array(
[tab]'post_author' => 123,
[tab]'post_status' => 'publish',
);

$query = new WP_Query( $args );
```

Expand Down Expand Up @@ -462,7 +462,7 @@ When using the `::class` constant for class name resolution, the `class` keyword
// Correct.
add_action( 'action_name', array( __CLASS__, 'method_name' ) );
add_action( 'action_name', array( My_Class::class, 'method_name' ) );

// Incorrect.
require_once __dIr__ . '/relative-path/file-name.php';
add_action( 'action_name', array( My_Class :: CLASS, 'method_name' ) );
Expand Down Expand Up @@ -525,7 +525,7 @@ namespace {
}
```

_There is currently no timeline for introducing namespaces to WordPress Core._
_There is currently no timeline for introducing namespaces to WordPress Core._

The use of namespaces in plugins and themes is strongly encouraged. It is a great way to prefix a lot of your code to prevent naming conflicts with other plugins, themes and/or WordPress Core.

Expand Down Expand Up @@ -582,7 +582,7 @@ Incorrect:
namespace Project_Name\Feature;

use const Project_Name\Sub_Feature\CONSTANT_A; // Superfluous whitespace after the "use" and the "const" keywords.
use function Project_Name\Sub_Feature\function_a; // Function import after constant import.
use function Project_Name\Sub_Feature\function_a; // Function import after constant import.
use \Project_Name\Sub_Feature\Class_C as aliased_class_c; // Leading backslash shouldn't be used, alias doesn't comply with naming conventions.
use Project_Name\Sub_Feature\{Class_D, Class_E as Aliased_Class_E} // Extra spaces around the "as" keyword, incorrect whitespace use inside the brace opener and closer.
use Vendor\Package\{ function function_a, function function_b,
Expand All @@ -600,12 +600,12 @@ use function Project_Name\Sub_Feature\function_b as Aliased_Function; // Import
```

[alert]
Import `use` statements have no effect on dynamic class, function or constant names.
Group `use` statements are available from PHP 7.0, and trailing commas in group `use` statements are available from PHP 7.2.
Import `use` statements have no effect on dynamic class, function or constant names.
Group `use` statements are available from PHP 7.0, and trailing commas in group `use` statements are available from PHP 7.2.
[/alert]

[info]
Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load whatever is being imported. You'll either need to set up autoloading or load the file containing the class/function/constant using a `require/import` statement, for the aliased constructs to be loaded when used.
Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load whatever is being imported. You'll either need to set up autoloading or load the file containing the class/function/constant using a `require/import` statement, for the imported constructs to be loaded when used.
[/info]

**Note about WordPres Core usage**
Expand All @@ -617,7 +617,7 @@ As neither of these are currently in place for WordPress Core and discussions ab

## Object-Oriented Programming

### Only One Object Structure (Class/Interface/Trait) per File
### Only One Object Structure (Class/Interface/Trait/Enum) per File

For instance, if we have a file called `class-example-class.php` it can only contain one class in that file.

Expand Down Expand Up @@ -736,11 +736,11 @@ When using multiple modifiers for a _method declaration_, the order should be as
// Correct.
abstract readonly class Foo {
private const LABEL = 'Book';

public static $foo;

private readonly string $bar;

abstract protected static function bar();
}

Expand All @@ -749,7 +749,7 @@ class Foo {
protected final const SLUG = 'book';

static public $foo;

static protected final function bar() {
// Code.
};
Expand Down

0 comments on commit 79f8ab4

Please sign in to comment.