1 | <?php |
||
2 | /** |
||
3 | * Smarty Plugin Data |
||
4 | * This file contains the data object |
||
5 | * |
||
6 | * @package Smarty |
||
7 | * @subpackage Template |
||
8 | * @author Uwe Tews |
||
9 | */ |
||
10 | |||
11 | /** |
||
12 | * class for the Smarty data object |
||
13 | * The Smarty data object will hold Smarty variables in the current scope |
||
14 | * |
||
15 | * @package Smarty |
||
16 | * @subpackage Template |
||
17 | */ |
||
18 | class Smarty_Data extends Smarty_Internal_Data |
||
19 | { |
||
20 | /** |
||
21 | * Counter |
||
22 | * |
||
23 | * @var int |
||
24 | */ |
||
25 | public static $count = 0; |
||
26 | |||
27 | /** |
||
28 | * Data block name |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | public $dataObjectName = ''; |
||
33 | |||
34 | /** |
||
35 | * Smarty object |
||
36 | * |
||
37 | * @var Smarty |
||
38 | */ |
||
39 | public $smarty = null; |
||
40 | |||
41 | /** |
||
42 | * create Smarty data object |
||
43 | * |
||
44 | * @param Smarty|array $_parent parent template |
||
45 | * @param Smarty|Smarty_Internal_Template $smarty global smarty instance |
||
46 | * @param string $name optional data block name |
||
47 | * |
||
48 | * @throws SmartyException |
||
49 | */ |
||
50 | public function __construct($_parent = null, $smarty = null, $name = null) |
||
51 | { |
||
52 | parent::__construct(); |
||
53 | self::$count++; |
||
54 | $this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count); |
||
55 | $this->smarty = $smarty; |
||
0 ignored issues
–
show
|
|||
56 | if (is_object($_parent)) { |
||
57 | // when object set up back pointer |
||
58 | $this->parent = $_parent; |
||
59 | } elseif (is_array($_parent)) { |
||
60 | // set up variable values |
||
61 | foreach ($_parent as $_key => $_val) { |
||
62 | $this->tpl_vars[ $_key ] = new Smarty_Variable($_val); |
||
63 | } |
||
64 | } elseif ($_parent !== null) { |
||
65 | throw new SmartyException('Wrong type for template variables'); |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.