Skip to content

[JsonStreamer] Stream reader not updated when object change #62030

@MatTheCat

Description

@MatTheCat

Symfony version(s) affected

7.3.0

Description

Generated stream readers filename depend on the type name:

private function getPath(Type $type, bool $decodeFromStream): string
{
return \sprintf('%s%s%s.json%s.php', $this->streamReadersDir, \DIRECTORY_SEPARATOR, hash('xxh128', (string) $type), $decodeFromStream ? '.stream' : '');
}

That means adding or removing a property from an object won’t result in another stream reader being generated, and trying to decode such an object will fail.

This is only an issue in dev env when you will change files without refreshing caches.

How to reproduce

Given a Test class

class Test
{
    public int $id;
}
$test = $reader->read('{"id": 1, "foo": "bar"}', Type::object(Test::class));
dump($test->id);

will correctly display 1.

Now adding a public string $foo property to Test, displaying $test->foo would result in

Typed property Test::$foo must not be accessed before initialization

Possible Solution

No response

Additional Context

No response

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