| 1 | <?php |
||
| 10 | class DivisionByOne implements AnalyzerPassInterface |
||
| 11 | { |
||
| 12 | use DefaultMetadataPassTrait; |
||
| 13 | |||
| 14 | const DESCRIPTION = 'Checks for division by 1. For example: `$x/1`, `$x%true`'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param Expr $expr |
||
| 18 | * @param Context $context |
||
| 19 | * @return bool |
||
| 20 | */ |
||
| 21 | 103 | public function pass(Expr $expr, Context $context) |
|
| 43 | |||
| 44 | /** |
||
| 45 | * @return array |
||
| 46 | */ |
||
| 47 | 1 | public function getRegister() |
|
| 56 | } |
||
| 57 |
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: