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

Closed
opened 2026-01-22 13:04:36 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 15, 2010).

Originally assigned to: @Ocramius on GitHub.

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

Originally created by @doctrinebot on GitHub (Dec 15, 2010). Originally assigned to: @Ocramius on GitHub. 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
admin added the BugInvalid labels 2026-01-22 13:04:36 +01:00
admin closed this issue 2026-01-22 13:04:37 +01:00
Author
Owner

@stloyd commented on GitHub (Dec 8, 2015):

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.

@stloyd commented on GitHub (Dec 8, 2015): 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`.
Author
Owner

@Ocramius commented on GitHub (Dec 9, 2015):

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 commented on GitHub (Dec 9, 2015): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1171