Closed
Description
Symfony version(s) affected
6.3.1
Description
I got an exception when I try to access a "static" properties.
Typed property App\Lazy\Lazy::$a must not be accessed before initialization
How to reproduce
With this code
<?php
namespace App\Lazy;
class Lazy
{
private int $a;
public function __construct(
private readonly Deps $deps,
) {
dump(__METHOD__);
$this->a = 1;
}
public function do(): int
{
// $this->deps->do();
return $this->doPrivate();
}
private function doPrivate(): int
{
return $this->a;
}
}
And the configuration
service:
App\Lazy\Lazy:
lazy: true
It throw an exception.
see this commit for a better reproducer
WARNING
It does work if I clear the cache, but If I add a new property, it does not work anymore.
So to reproduce
-
run the app
-
apply this patch (without cleanring the cache)
diff --git a/src/Lazy/Lazy.php b/src/Lazy/Lazy.php index f40f60a..b2ed79c 100644 --- a/src/Lazy/Lazy.php +++ b/src/Lazy/Lazy.php @@ -5,16 +5,19 @@ namespace App\Lazy; class Lazy { private int $a; + private int $b; public function __construct( private readonly Deps $deps, ) { dump(__METHOD__); $this->a = 1; + $this->b = 1; } public function do(): int { + $this->b; // $this->deps->do(); return $this->doPrivate();
-
refresh the page