| 1 | <?php |
||
| 21 | class UniquePriorityQueue extends PriorityQueue |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * {@inheritDoc} |
||
| 25 | */ |
||
| 26 | public function count() |
||
| 30 | |||
| 31 | /** |
||
| 32 | * {@inheritDoc} |
||
| 33 | */ |
||
| 34 | public function getIterator() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Remove duplicated items |
||
| 44 | * |
||
| 45 | * @param array $input |
||
| 46 | * @return array |
||
| 47 | */ |
||
| 48 | protected function getUnique(array $input): array |
||
| 63 | } |
||
| 64 |
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: