| 1 | <?php |
||
| 18 | class EmptyResponse implements QueryResponse |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var EmptyResponse The reference to *Singleton* instance of this class |
||
| 22 | */ |
||
| 23 | private static $instance; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Protected constructor to prevent creating a new instance of the |
||
| 27 | * *Singleton* via the `new` operator from outside of this class. |
||
| 28 | */ |
||
| 29 | protected function __construct() |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Returns the *Singleton* instance of this class. |
||
| 35 | * |
||
| 36 | * @return EmptyResponse The *Singleton* instance |
||
| 37 | */ |
||
| 38 | public static function create() : EmptyResponse |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Private clone method to prevent cloning of the instance of the |
||
| 49 | * *Singleton* instance. |
||
| 50 | * |
||
| 51 | * @codeCoverageIgnore |
||
| 52 | */ |
||
| 53 | private function __clone() |
||
| 56 | } |
||
| 57 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClassto useselfinstead: