Skip to content

[VarExporter] Ghost fails when calling internal property when not initialized yet #50792

Closed
@lyrixx

Description

@lyrixx

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

  1. run the app

  2. 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();
  3. refresh the page

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions