10000 [GhostProxy] error cannot assign by reference to overloaded object · Issue #51048 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[GhostProxy] error cannot assign by reference to overloaded object #51048

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
vtsykun opened this issue Jul 20, 2023 · 1 comment
Closed

[GhostProxy] error cannot assign by reference to overloaded object #51048

vtsykun opened this issue Jul 20, 2023 · 1 comment

Comments

@vtsykun
Copy link
Contributor
vtsykun commented Jul 20, 2023

Symfony version(s) affected

6.3.1

Description

This error occurs if the proxy is initialized from trait. See STR below
Selection_1641

How to reproduce

Create classes

    App\B1Class:
        arguments: ['test1']
        calls:
            - [setProp2, ['test2']]
        lazy: true
trait B1Trait
{
    protected $prop2;

    protected function getProp2()
    {
        return $this->prop2;
    }

    public function setProp2($prop2)
    {
        $this->prop2 = $prop2;
    }
}

class A1Class {
    private $prop1;
    public function __construct($prop1)
    {
        $this->prop1 = $prop1;
    }
}

class B1Class extends A1Class
{
    use B1Trait;
    protected $prop1;

    public function __construct($prop1)
    {
        parent::__construct($prop1);
        $this->prop1 = $prop1;
    }

    public function test()
    {
        $this->getProp2();

        return $this->prop1;
    }
}

And call service B1Class->test()

Possible Solution

No response

Additional Context

Error:
Cannot assign by reference to overloaded object

  at vendor/symfony/var-exporter/Internal/Hydrator.php:165
  at Packeton\Util\A1Class->Symfony\Component\VarExporter\Internal\{closure}()
     (vendor/symfony/var-exporter/Hydrator.php:72)
  at Symfony\Component\VarExporter\Hydrator::hydrate()
     (vendor/symfony/var-exporter/Internal/LazyObjectState.php:94)
  at Symfony\Component\VarExporter\Internal\LazyObjectState->initialize()
     (vendor/symfony/var-exporter/LazyGhostTrait.php:176)
  at ContainerWf1jvVR\B1ClassGhostD578c3f->__get()
     (src/Util/B1Class.php:11)
  at Packeton\Util\B1Class->getProp2()
     (src/Util/B1Class.php:41)
  at Packeton\Util\B1Class->test()
     (src/Controller/UserController.php:70)
  at Packeton\Controller\UserController->showAction()
     (vendor/symfony/http-kernel/HttpKernel.php:166)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (vendor/symfony/http-kernel/HttpKernel.php:74)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (vendor/symfony/http-kernel/Kernel.php:197)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:29)
  at require_once('/var/www/packeton5/vendor/autoload_runtime.php')
     (public/index.php:5)   
@MatTheCat
Copy link
Contributor

The issue does not come from the trait but $prop1 which is private in the parent and protected in the child class. Not sure why yet.

nicolas-grekas added a commit that referenced this issue Jul 26, 2023
…essors (vtsykun)

This PR was submitted for the 6.3 branch but it was merged into the 6.2 branch instead.

Discussion
----------

[VarExporter] Fix calling scope detection inside magic accessors

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

This PR provides fixes related to detection of class scope for which the magic method was called.
this fixes are related to the issue described in this RFC https://wiki.php.net/rfc/access_scope_from_magic_accessors

more accurate STR for the bug:

```php
class A1Class {
    private $prop1;
    public function __construct($prop1)
    {
        $this->prop1 = $prop1;
    }

    public function getProp1()
    {
        return $this->prop1;
    }
}

class B1Class extends A1Class
{
    protected $prop1;
    protected $prop2;

    public function __construct($prop1)
    {
        parent::__construct($prop1);
        $this->prop1 = $prop1;
    }

    public function test()
    {
        return $this->prop1;
    }

    public function test2()
    {
        return $this->prop2;
    }

    public function setProp2($prop2)
    {
        $this->prop2 = $prop2;
    }
}
```

```yml
    App\B1Class:
        arguments: [ 'test1' ]
        calls:
            - [ setProp2, [ 'test2' ] ]
        lazy: true
```

Call `$this->b1Class->test2();`

Actual result:
![Selection_1645](https://github.com/symfony/symfony/assets/21358010/db71f9c3-cfec-4f1e-b638-e10b9384fef9)

Commits
-------

41e3615 [VarDumper] Fix calling scope detection inside magic accessors
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

5 participants
0