1 | <?php |
||
13 | class Text_Diff_Renderer |
||
14 | { |
||
15 | /** |
||
16 | * Number of leading context "lines" to preserve. |
||
17 | * |
||
18 | * This should be left at zero for this class, but subclasses may want to |
||
19 | * set this to other values. |
||
20 | */ |
||
21 | public $_leading_context_lines = 0; |
||
22 | |||
23 | /** |
||
24 | * Number of trailing context "lines" to preserve. |
||
25 | * |
||
26 | * This should be left at zero for this class, but subclasses may want to |
||
27 | * set this to other values. |
||
28 | */ |
||
29 | public $_trailing_context_lines = 0; |
||
30 | |||
31 | /** |
||
32 | * Constructor. |
||
33 | * @param array $params |
||
34 | */ |
||
35 | public function __construct($params = array()) |
||
44 | |||
45 | /** |
||
46 | * Get any renderer parameters. |
||
47 | * |
||
48 | * @return array All parameters of this renderer object. |
||
49 | */ |
||
50 | public function getParams() |
||
61 | |||
62 | /** |
||
63 | * Renders a diff. |
||
64 | * |
||
65 | * @param Text_Diff $diff A Text_Diff object. |
||
66 | * |
||
67 | * @return string The formatted output. |
||
68 | */ |
||
69 | public function render($diff) |
||
122 | |||
123 | /** |
||
124 | * @param $xbeg |
||
125 | * @param $xlen |
||
126 | * @param $ybeg |
||
127 | * @param $ylen |
||
128 | * @param $edits |
||
129 | * @return string |
||
130 | */ |
||
131 | public function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) |
||
157 | |||
158 | /** |
||
159 | * @return string |
||
160 | */ |
||
161 | public function _startDiff() |
||
165 | |||
166 | /** |
||
167 | * @return string |
||
168 | */ |
||
169 | public function _endDiff() |
||
173 | |||
174 | /** |
||
175 | * @param $xbeg |
||
176 | * @param $xlen |
||
177 | * @param $ybeg |
||
178 | * @param $ylen |
||
179 | * @return string |
||
180 | */ |
||
181 | public function _blockHeader($xbeg, $xlen, $ybeg, $ylen) |
||
192 | |||
193 | /** |
||
194 | * @param $header |
||
195 | * @return string |
||
196 | */ |
||
197 | public function _startBlock($header) |
||
201 | |||
202 | /** |
||
203 | * @return string |
||
204 | */ |
||
205 | public function _endBlock() |
||
209 | |||
210 | /** |
||
211 | * @param $lines |
||
212 | * @param string $prefix |
||
213 | * @return string |
||
214 | */ |
||
215 | public function _lines($lines, $prefix = ' ') |
||
219 | |||
220 | /** |
||
221 | * @param $lines |
||
222 | * @return string |
||
223 | */ |
||
224 | public function _context($lines) |
||
228 | |||
229 | /** |
||
230 | * @param $lines |
||
231 | * @return string |
||
232 | */ |
||
233 | public function _added($lines) |
||
237 | |||
238 | /** |
||
239 | * @param $lines |
||
240 | * @return string |
||
241 | */ |
||
242 | public function _deleted($lines) |
||
246 | |||
247 | /** |
||
248 | * @param $orig |
||
249 | * @param $final |
||
250 | * @return string |
||
251 | */ |
||
252 | public function _changed($orig, $final) |
||
256 | } |
||
257 |
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: