| 1 | <?php |
||
| 8 | class UserRequest extends FormRequest |
||
| 9 | { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Get the validation rules that apply to the request. |
||
| 13 | * |
||
| 14 | * @return array |
||
| 15 | */ |
||
| 16 | public function rules() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Determine if the user is authorized to make this request. |
||
| 52 | * |
||
| 53 | * @return bool |
||
| 54 | */ |
||
| 55 | public function authorize() |
||
| 59 | |||
| 60 | } |
||
| 61 |
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: