| 1 | <?php |
||
| 18 | class Process |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var Factory |
||
| 22 | */ |
||
| 23 | private $factory; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Process constructor. |
||
| 27 | * @param Factory $factory |
||
| 28 | */ |
||
| 29 | public function __construct(Factory $factory) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param ContextInterface $ctx |
||
| 36 | * @param mixed $result |
||
| 37 | * @return array |
||
| 38 | */ |
||
| 39 | public function run(ContextInterface $ctx, $result): array |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param ContextInterface $ctx |
||
| 50 | * @param \Generator $process |
||
| 51 | * @return array |
||
| 52 | */ |
||
| 53 | public function await(ContextInterface $ctx, \Generator $process): array |
||
| 67 | } |
||
| 68 |
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.