1 | <?php |
||
7 | class DestinationRegistry |
||
8 | { |
||
9 | /** |
||
10 | * @var null|DestinationRegistry |
||
11 | */ |
||
12 | private static $instance = null; |
||
13 | |||
14 | /** |
||
15 | * @var Destination[] |
||
16 | */ |
||
17 | protected $destinations = []; |
||
18 | |||
19 | /** |
||
20 | * @return DestinationRegistry |
||
21 | */ |
||
22 | public static function instance(): DestinationRegistry |
||
30 | |||
31 | /** |
||
32 | * @param string $name |
||
33 | * @param Destination $destination |
||
34 | */ |
||
35 | public function set(string $name, Destination $destination) |
||
39 | |||
40 | /** |
||
41 | * @param string $name |
||
42 | * @return Destination |
||
43 | */ |
||
44 | public function get(string $name): Destination |
||
57 | } |
||
58 |
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
SomeClass
to useself
instead: