diff --git a/wordpress-coding-standards/php.md b/wordpress-coding-standards/php.md index 69f17b8..f6f7178 100644 --- a/wordpress-coding-standards/php.md +++ b/wordpress-coding-standards/php.md @@ -755,6 +755,23 @@ abstract class Foo { } ``` +### Object instantiation + +When instantiating a new object instance, parenthesis must always be used, even when not strictly necessary. +There should be no space between the name of the class being instantiated and the opening parenthesis. +Assigning the return value of an object instantiation by reference is not allowed (new by reference has not been supported by PHP for quite a long while now). + +```php +// Correct. +$foo = new Foo(); +$anonymous_class = new class() { ... }; +$instance = new static(); + +// Incorrect. +$foo = & new Foo; +$foo = new Foo (); +``` + ## Control Structures ### Use `elseif`, not `else if`