Skip to content

Commit

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

0 comments on commit 84ef00c

Please sign in to comment.