1 | <?php |
||
15 | class Attribute implements AttributeInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $name; |
||
21 | |||
22 | /** |
||
23 | * @var int |
||
24 | */ |
||
25 | private $type; |
||
26 | |||
27 | /** |
||
28 | * @var Matchable |
||
29 | */ |
||
30 | private $matcher; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $camel; |
||
36 | |||
37 | /** |
||
38 | * Attribute constructor. |
||
39 | * @param string $name |
||
40 | * @param int $type |
||
41 | */ |
||
42 | public function __construct(string $name, int $type = self::TYPE_UNDEFINED) |
||
48 | |||
49 | /** |
||
50 | * @param string $name |
||
51 | * @return string |
||
52 | */ |
||
53 | private function toCamelCase(string $name): string |
||
60 | |||
61 | /** |
||
62 | * @param mixed|object $context |
||
63 | * @return mixed |
||
64 | */ |
||
65 | public function getValueFrom($context) |
||
80 | |||
81 | /** |
||
82 | * @param mixed $context |
||
83 | * @return mixed |
||
84 | */ |
||
85 | private function getFromAttribute($context) |
||
91 | |||
92 | /** |
||
93 | * @return string |
||
94 | */ |
||
95 | private function getPropertyGetter(): string |
||
99 | |||
100 | /** |
||
101 | * @param object $context |
||
102 | * @param string $getter |
||
103 | * @param mixed $value |
||
104 | * @return mixed |
||
105 | */ |
||
106 | private function getUsingGetter($context, string $getter, $value) |
||
112 | |||
113 | /** |
||
114 | * @return string |
||
115 | */ |
||
116 | private function getBooleanGetter(): string |
||
120 | |||
121 | /** |
||
122 | * @param mixed|object $context |
||
123 | * @param mixed $value |
||
124 | * @return void |
||
125 | */ |
||
126 | public function setValueTo($context, $value): void |
||
136 | |||
137 | /** |
||
138 | * @return string |
||
139 | */ |
||
140 | private function getPropertySetter(): string |
||
144 | |||
145 | /** |
||
146 | * @param object $context |
||
147 | * @param string $setter |
||
148 | * @param mixed $value |
||
149 | * @return void |
||
150 | */ |
||
151 | private function setUsingSetter($context, string $setter, $value): void |
||
157 | |||
158 | /** |
||
159 | * @param object $context |
||
160 | * @param mixed $value |
||
161 | */ |
||
162 | private function setToAttribute($context, $value): void |
||
168 | |||
169 | /** |
||
170 | * @param Matchable $hint |
||
171 | * @return Matchable |
||
172 | */ |
||
173 | public function addMatcher(Matchable $hint): Matchable |
||
179 | |||
180 | /** |
||
181 | * @return bool |
||
182 | */ |
||
183 | public function isReadable(): bool |
||
187 | |||
188 | /** |
||
189 | * @return bool |
||
190 | */ |
||
191 | public function isWritable(): bool |
||
195 | |||
196 | /** |
||
197 | * @param mixed $value |
||
198 | * @return bool |
||
199 | */ |
||
200 | public function match($value): bool |
||
208 | |||
209 | /** |
||
210 | * @return string |
||
211 | */ |
||
212 | public function getName(): string |
||
216 | } |
||
217 |
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.