1 | <?php |
||
12 | class Handshake { |
||
13 | |||
14 | const RFC_GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $buffer = ''; |
||
20 | |||
21 | /** |
||
22 | * @var WebSocketClient |
||
23 | */ |
||
24 | protected $client; |
||
25 | |||
26 | /** |
||
27 | * @var string[] |
||
28 | */ |
||
29 | protected $headers = []; |
||
30 | |||
31 | /** |
||
32 | * The connection is closed (HTTP 413) if the received headers exceed this many bytes. |
||
33 | * |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $maxLength = 4096; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $method; |
||
42 | |||
43 | /** |
||
44 | * @param WebSocketClient $client |
||
45 | */ |
||
46 | public function __construct (WebSocketClient $client) { |
||
49 | |||
50 | /** |
||
51 | * @return string[] |
||
52 | */ |
||
53 | public function getHeaders () { |
||
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | public function getMethod (): string { |
||
63 | |||
64 | /** |
||
65 | * Negotiates the initial connection. |
||
66 | * |
||
67 | * @return bool |
||
68 | * @throws WebSocketError |
||
69 | * @throws Throwable |
||
70 | */ |
||
71 | public function onReadable (): bool { |
||
128 | |||
129 | /** |
||
130 | * Sends the connection upgrade headers. |
||
131 | */ |
||
132 | protected function upgrade (): void { |
||
141 | |||
142 | /** |
||
143 | * Validates the received HTTP handshake headers, or throws. |
||
144 | * |
||
145 | * @throws WebSocketError |
||
146 | */ |
||
147 | protected function validate (): void { |
||
163 | } |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: