1 | <?php |
||
11 | class CodeTable extends LazyResource |
||
12 | { |
||
13 | /** @var string */ |
||
14 | public $code; |
||
15 | |||
16 | /** |
||
17 | * CodeTable constructor. |
||
18 | * |
||
19 | * @param Client $client |
||
20 | * @param string $code |
||
21 | */ |
||
22 | public function __construct(Client $client, $code) |
||
27 | |||
28 | /** |
||
29 | * Return a single row referring to the code table. |
||
30 | * |
||
31 | * @param $code - The code in the Table we want to pull. |
||
32 | * |
||
33 | * @return object - the row in the code table. |
||
34 | */ |
||
35 | public function getRowByCode($code) |
||
49 | |||
50 | /** |
||
51 | * Check if we have the full representation of our data object. |
||
52 | * |
||
53 | * @param \stdClass $data |
||
54 | * |
||
55 | * @return bool |
||
56 | */ |
||
57 | protected function isInitialized($data) |
||
61 | |||
62 | /** |
||
63 | * Generate the base URL for this resource. |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | protected function urlBase() |
||
71 | |||
72 | } |
||
73 |
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: