1 | <?php |
||
8 | class GatewayRegistry |
||
9 | { |
||
10 | /** |
||
11 | * @var null|GatewayRegistry |
||
12 | */ |
||
13 | private static $instance = null; |
||
14 | |||
15 | /** |
||
16 | * @var Gateway[] |
||
17 | */ |
||
18 | protected $gateways = []; |
||
19 | |||
20 | /** |
||
21 | * @return GatewayRegistry |
||
22 | */ |
||
23 | public static function instance(): GatewayRegistry |
||
31 | |||
32 | /** |
||
33 | * @param Gateway $gateway |
||
34 | */ |
||
35 | 4 | public function set(Gateway $gateway) |
|
39 | |||
40 | /** |
||
41 | * @param Destination $destination |
||
42 | * @return Gateway |
||
43 | */ |
||
44 | 5 | public function get(Destination $destination): Gateway |
|
58 | } |
||
59 |
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: