1 | <?php |
||
17 | class Field implements FieldInterface, \IteratorAggregate |
||
18 | { |
||
19 | /** |
||
20 | * Inherit value delimiter |
||
21 | */ |
||
22 | public const DEEP_DELIMITER = '.'; |
||
23 | |||
24 | /** |
||
25 | * Prefix using for disable aliasing field |
||
26 | */ |
||
27 | public const NON_ALIASED_PREFIX = ':'; |
||
28 | |||
29 | /** |
||
30 | * @var array|string[] |
||
31 | */ |
||
32 | private $chunks = []; |
||
33 | |||
34 | /** |
||
35 | * @var bool |
||
36 | */ |
||
37 | private $prefixed = true; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | private $wrapper = ''; |
||
43 | |||
44 | /** |
||
45 | * Field constructor. |
||
46 | * @param string $query |
||
47 | */ |
||
48 | 77 | public function __construct(string $query) |
|
58 | |||
59 | /** |
||
60 | * @param string $query |
||
61 | * @return void |
||
62 | */ |
||
63 | 77 | private function analyseAndFill(string $query): void |
|
78 | |||
79 | /** |
||
80 | * @param Lexer $lexer |
||
81 | * @return \Generator|string[] |
||
82 | */ |
||
83 | 77 | private function analyse(Lexer $lexer): \Generator |
|
122 | |||
123 | /** |
||
124 | * @param Lexer $lexer |
||
125 | * @return \Generator |
||
126 | */ |
||
127 | 77 | private function lex(Lexer $lexer): \Generator |
|
137 | |||
138 | /** |
||
139 | * @param string $query |
||
140 | * @return Field |
||
141 | */ |
||
142 | 11 | public static function new(string $query): self |
|
146 | |||
147 | /** |
||
148 | * @return string |
||
149 | */ |
||
150 | 77 | public function getName(): string |
|
154 | |||
155 | /** |
||
156 | * @param string|null $alias |
||
157 | * @return string |
||
158 | */ |
||
159 | 76 | public function toString(string $alias = null): string |
|
167 | |||
168 | /** |
||
169 | * @return bool |
||
170 | */ |
||
171 | 13 | public function isPrefixed(): bool |
|
175 | |||
176 | /** |
||
177 | * @return string |
||
178 | */ |
||
179 | 1 | public function __toString(): string |
|
183 | |||
184 | /** |
||
185 | * @return iterable|Field[] |
||
186 | */ |
||
187 | 4 | public function getIterator(): iterable |
|
198 | } |
||
199 |
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,
$x
would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.