Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@MatTheCat

Description

@MatTheCat
Issue body actions

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

mtarld

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.