| Conditions | 4 |
| Paths | 4 |
| Total Lines | 27 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public function renderTemplate(Plates\Template $template) { |
||
| 25 | $this->hydrate->hydrateTemplate($template); |
||
| 26 | |||
| 27 | $ctx = call_user_func($this->create_render_context, $this, $template); |
||
| 28 | |||
| 29 | if (array_key_exists($this->render_context_var_name, $data)) { |
||
|
|
|||
| 30 | throw new Plates\Exception\PlatesException('Cannot set render context because a variable already exists as ' . $this->render_context_var_name); |
||
| 31 | } |
||
| 32 | $data[$this->render_context_var_name] = $ctx; |
||
| 33 | |||
| 34 | // this is done for BC reasons} |
||
| 35 | $include = $this->include->bindTo($ctx); |
||
| 36 | |||
| 37 | try { |
||
| 38 | return $include($path, $data); |
||
| 39 | } catch (Exception $e) { |
||
| 40 | |||
| 41 | } catch (Throwable $e) { |
||
| 42 | |||
| 43 | } |
||
| 44 | |||
| 45 | throw new Plates\Exception\PlatesException( |
||
| 46 | 'An exception occurred while rendering Template ' . $template->name . '.', |
||
| 47 | 0, |
||
| 48 | $e |
||
| 49 | ); |
||
| 50 | } |
||
| 51 | } |
||
| 52 |
This error can happen if you refactor code and forget to move the variable initialization.
Let’s take a look at a simple example:
The above code is perfectly fine. Now imagine that we re-order the statements:
In that case,
$xwould be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.