Skip to content

Loading…

DDC-940: Entities can / can not have private properties #5470

Closed
doctrinebot opened this Issue · 2 comments

3 participants

@doctrinebot

Jira issue originally created by user tech13:

In the note in
http://www.doctrine-project.org/docs/orm/2.0/en/reference/working-with-objects.html#merging-entities
It appears to state that private variables are not serialized for child objects

If this is the only reason entities can't have private properties, then this restriction is no longer valid, or possibly be reconsidered.

<?php

class A {
    private $a = null;

    public function setValue($value) {
        $this->a = $value;
    }
}

class B extends A {}

$b = new B();
$b->setValue("B");
var_dump($b);

$c = unserialize(serialize($b));
var_dump($c);

The output suggests private variables are serialized, and are restored fine

@stloyd

This totally correct behavior of PHP language. private variable are not visible for class that extend parent, if you want to see them you need to mark them as protected.

@Ocramius
Doctrine member

Indeed: https://3v4l.org/Ha3qj

Also, this was already fixed (we deal with merging private state, AFAIK).

Closing, unless somebody comes up with a failing test case.

@Ocramius Ocramius closed this
@Ocramius Ocramius self-assigned this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.