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 | * [ header name => lowercase value => actual value ] |
||
28 | * |
||
29 | * @var string[][] |
||
30 | */ |
||
31 | protected $headers = []; |
||
32 | |||
33 | /** |
||
34 | * The connection is closed (HTTP 413) if the received headers exceed this many bytes. |
||
35 | * |
||
36 | * @var int |
||
37 | */ |
||
38 | protected $maxLength = 4096; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $method; |
||
44 | |||
45 | /** |
||
46 | * @param WebSocketClient $client |
||
47 | */ |
||
48 | public function __construct (WebSocketClient $client) { |
||
51 | |||
52 | /** |
||
53 | * @return string[][] |
||
54 | */ |
||
55 | public function getHeaders () { |
||
58 | |||
59 | /** |
||
60 | * @return string |
||
61 | */ |
||
62 | public function getMethod (): string { |
||
65 | |||
66 | /** |
||
67 | * Negotiates the initial connection. |
||
68 | * |
||
69 | * @return bool |
||
70 | * @throws WebSocketError |
||
71 | * @throws Throwable |
||
72 | */ |
||
73 | public function onReadable (): bool { |
||
127 | |||
128 | /** |
||
129 | * Sends the connection upgrade headers. |
||
130 | */ |
||
131 | protected function upgrade (): void { |
||
140 | |||
141 | /** |
||
142 | * Validates the received HTTP handshake headers, or throws. |
||
143 | * |
||
144 | * @throws WebSocketError |
||
145 | */ |
||
146 | protected function validate (): void { |
||
162 | } |
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: