| 1 | <?php |
||
| 6 | class LengthBetweenTester implements Tester |
||
| 7 | { |
||
| 8 | /** @var int */ |
||
| 9 | protected $min; |
||
| 10 | |||
| 11 | /** @var int */ |
||
| 12 | protected $max; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param int $min |
||
| 16 | * @param int $max |
||
| 17 | */ |
||
| 18 | 1 | public function __construct($min, $max) |
|
| 23 | |||
| 24 | /** |
||
| 25 | * {@inheritdoc} |
||
| 26 | */ |
||
| 27 | 1 | public function test($data, $origin = null, array $keys = []): bool |
|
| 36 | } |
||
| 37 |
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: