Skip to content

Serialization of private parent variables #16

@gnat42

Description

@gnat42

So recently I've spent a few hours trying to figure out why I was having issues unserializing data that was serialized properly. It took awhile to figure it out. Here's an example.

``
class AbstractCommand
{
private $someVar;
public function getSomeVar(){ return $this->someVar; }
}

class ChildCommand extends AbstractCommand
{
}
``

If you serialize ChildCommand you get
{"@type":"ChildCommand","someVar":{"@scalar":"integer","@value":19}}

but if you unserialize it, you get a ChildCommand object with a null someVar. The issue is that then on line 405 of your Serializer class, you get an exception because that var doesn't exist. Because the variable is private to AbstractCommand. So I'm not sure how to solve this, however it took hours to track down what's going on. So either the situation needs to be detected, or some other type of solution that I'm not aware of.

I don't know why it can get the variable but not set it.

If you need a PR of a failing test case I can probably do that as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions