1 | <?php |
||
13 | class SparkPlug |
||
14 | { |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $constants = array(); |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $globals = array(); |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $path = ''; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $server = array(); |
||
34 | |||
35 | /** |
||
36 | * @param array $globals |
||
37 | * @param array $server |
||
38 | * @param string|null $path |
||
39 | */ |
||
40 | 24 | public function __construct(array &$globals, array $server, $path = null) |
|
56 | |||
57 | /** |
||
58 | * Returns the Codeigniter singleton. |
||
59 | * NOTE: To be removed in v1.0.0. Use instance() instead. |
||
60 | * |
||
61 | * @return \CI_Controller |
||
62 | */ |
||
63 | 12 | public function getCodeIgniter() |
|
67 | |||
68 | /** |
||
69 | * Returns the Codeigniter singleton. |
||
70 | * |
||
71 | * @return \CI_Controller |
||
72 | */ |
||
73 | 24 | public function instance() |
|
93 | |||
94 | /** |
||
95 | * Sets the constant with a value. |
||
96 | * |
||
97 | * @param string $key |
||
98 | * @param string $value |
||
99 | */ |
||
100 | 12 | public function set($key, $value) |
|
106 | |||
107 | /** |
||
108 | * Sets the base path. |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | 3 | protected function basepath() |
|
128 | |||
129 | /** |
||
130 | * Sets up important charset-related stuff. |
||
131 | * |
||
132 | * @return void |
||
133 | */ |
||
134 | 24 | protected function charset() |
|
148 | |||
149 | /** |
||
150 | * Loads the Common and the Base Controller class. |
||
151 | * |
||
152 | * @return void |
||
153 | */ |
||
154 | 24 | protected function common() |
|
164 | |||
165 | /** |
||
166 | * Sets global configurations. |
||
167 | * |
||
168 | * @return void |
||
169 | */ |
||
170 | 24 | protected function config() |
|
180 | |||
181 | /** |
||
182 | * Loads the framework constants. |
||
183 | * |
||
184 | * @return void |
||
185 | */ |
||
186 | 24 | protected function constants() |
|
196 | |||
197 | /** |
||
198 | * Loads the CodeIgniter's core classes. |
||
199 | * |
||
200 | * @return void |
||
201 | */ |
||
202 | 24 | protected function core() |
|
212 | |||
213 | /** |
||
214 | * Sets up the current environment. |
||
215 | * |
||
216 | * @return void |
||
217 | */ |
||
218 | 24 | protected function environment($value = 'development') |
|
224 | |||
225 | /** |
||
226 | * Sets up the APPPATH, VENDOR, and BASEPATH constants. |
||
227 | * |
||
228 | * @return void |
||
229 | */ |
||
230 | 24 | protected function paths() |
|
248 | } |
||
249 |
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: