Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] #44283

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
webmake opened this issue Nov 25, 2021 · 4 comments · Fixed by #44295
Closed

[Serializer] #44283

webmake opened this issue Nov 25, 2021 · 4 comments · Fixed by #44295

Comments

@webmake
Copy link

webmake commented Nov 25, 2021

Symfony version(s) affected

4.4.35

Description

After migrating from v4.4.31 to v4.4.35 broke some functionality for private variables.

How to reproduce

        $x = new class
        {
            private ArrayCollection $__loaders;

            public function __setLoaders(ArrayCollection $loaders)
            {
                $this->__loaders = $loaders;
            }

            public function __call($name, $arguments)
            {
                if ($this->__loaders && ($loader = $this->__loaders->get($name)) !== null) {
                    return $loader->load();
                }

                throw new \BadMethodCallException(static::class . '->' . $name . '() method not found');
            }

            public function __get(string $name)
            {
                if ($this->__loaders && $this->__loaders->get($name) !== null) {
                    return $this->__call($name, []);
                }

                if (strpos($name, 'get') !== 0) {
                    $name = 'get' . ucfirst($name);
                }

                return $this->__call($name, []);
            }
        };
        $x->__setLoaders(new ArrayCollection([
            'a' => new class {
                public function load()
                {
                    return 'a';
                }
            },
        ]));
        $x->a(); // works
        $this->serializer->serialize($x, 'json'); // error

Occurs an error:
"class@anonymous/home/docker/sample/src/Sample.php:51$901a0->get__loaders() method not found"
because in previous version private variables was not supposed to be serialized

Possible Solution

No response

Additional Context

It most likely related to this commit because removed

            if (!$isPublic) {
                continue;
            }

but you can see full changes for this migration that arises error.

@IonBazan
Copy link
Contributor

This seems related to #44273.

@nicolas-grekas
Copy link
Member

Can you please confirm #44295 fixes the issue?

@nicolas-grekas nicolas-grekas linked a pull request Nov 26, 2021 that will close this issue
nicolas-grekas added a commit that referenced this issue Nov 28, 2021
…s-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[Serializer] fix support for lazy/unset properties

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

This basically backports #43469 into 4.4, which is the way to go to fix #44273.
The code that exists to handle uninitialized properties is broken anyway (it was before the recent changes.)

Commits
-------

db043aa [Serializer] fix support for lazy/unset properties
@webmake
Copy link
Author

webmake commented Dec 1, 2021

Yes, it seems that patch fixes somehow 👍 when we can expect at 4.4?

@xabbuh
Copy link
Member

xabbuh commented Dec 6, 2021

Patch releases are done once a month.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants