| 1 | <?php |
||
| 12 | class Ofx implements JsonSerializable |
||
| 13 | { |
||
| 14 | |||
| 15 | private $ofx; |
||
| 16 | |||
| 17 | private $movements = []; |
||
| 18 | |||
| 19 | public function __construct(SimpleXMLElement $xml) |
||
| 32 | |||
| 33 | public function getMovements(): array |
||
| 37 | |||
| 38 | private function exportMovements(SimpleXMLElement $xml): void |
||
| 44 | |||
| 45 | public function jsonSerialize() |
||
| 49 | } |
||
| 50 |
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: