Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lyrixx opened this issue Jun 27, 2023 · 0 comments
Closed

Comments

@lyrixx
Copy link
Member

lyrixx commented Jun 27, 2023

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

@lyrixx lyrixx added the Bug label Jun 27, 2023
nicolas-grekas added a commit that referenced this issue Jun 28, 2023
…ces (nicolas-grekas)

This PR was merged into the 6.2 branch.

Discussion
----------

[DependencyInjection] Fix resource tracking for lazy services

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #50792
| License       | MIT
| Doc PR        | -

Commits
-------

0f737d8 [DependencyInjection] Fix resource tracking for lazy services
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants