From 0f49b189de6238fa820d6a6f76372a8fa4f75f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Fri, 12 Aug 2022 15:56:59 +0200 Subject: [PATCH] Add fully qualified names in inline code chapter --- wordpress-coding-standards/php.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/wordpress-coding-standards/php.md b/wordpress-coding-standards/php.md index e65fed6..79fa17c 100644 --- a/wordpress-coding-standards/php.md +++ b/wordpress-coding-standards/php.md @@ -482,6 +482,24 @@ While import `use` statements can already be used in WordPress Core, it is, for Import `use` statements are most useful when combined with namespaces and a class autoloading implementation. As neither of these are currently in place for WordPress Core and discussions about this are ongoing, holding off on adding import `use` statements to WordPress Core is the sensible choice for now. +### Using fully qualified names in inline code + +When using a fully or partially qualified name, no whitespace or comments are allowed within the name. + +```php +// Correct. +$foo = new \Vendor\Domain\Foo(); + +$result = namespace\function_name(); + +// Incorrect. +$foo = new \Vendor // Source: external dependency. + \Domain + \Foo(); + +$result = namespace \function_name(); // Notice the space between namespace and \function_name(). +``` + ## Object-Oriented Programming ### Only One Object Structure (Class/Interface/Trait) per File