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

Skip to content

[Serializer] #44283

Closed
Closed
@webmake

Description

@webmake

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.

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