1 | <?php |
||
9 | class HybridSession extends BaseStore |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * List of session handlers |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $handlers = []; |
||
18 | |||
19 | /** |
||
20 | * True if this session store has been initialised |
||
21 | * |
||
22 | * @var bool |
||
23 | */ |
||
24 | protected static $enabled = false; |
||
25 | |||
26 | /** |
||
27 | * @param SessionHandlerInterface[] |
||
28 | * |
||
29 | * @return $this |
||
30 | */ |
||
31 | public function setHandlers($handlers) |
||
38 | |||
39 | /** |
||
40 | * @param string |
||
41 | * |
||
42 | * @return $this |
||
43 | */ |
||
44 | public function setKey($key) |
||
54 | |||
55 | /** |
||
56 | * @return SessionHandlerInterface[] |
||
57 | */ |
||
58 | public function getHandlers() |
||
62 | |||
63 | /** |
||
64 | * @param string $save_path |
||
65 | * @param string $name |
||
66 | * |
||
67 | * @return bool |
||
68 | */ |
||
69 | public function open($save_path, $name) |
||
77 | |||
78 | /** |
||
79 | * @return bool |
||
80 | */ |
||
81 | public function close() |
||
89 | |||
90 | /** |
||
91 | * @param string $session_id |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | public function read($session_id) |
||
105 | |||
106 | public function write($session_id, $session_data) |
||
116 | |||
117 | public function destroy($session_id) |
||
125 | |||
126 | public function gc($maxlifetime) |
||
132 | |||
133 | /** |
||
134 | * Register the session handler as the default |
||
135 | * |
||
136 | * @param string $key Desired session key |
||
137 | */ |
||
138 | public static function init($key = null) |
||
155 | |||
156 | public static function is_enabled() |
||
160 | } |
||
161 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: