DDC-883: "private" properties and proxy classes. #1096

Open
opened 2026-01-22 13:01:54 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 18, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user fumanchu182:

When creating entities I usually create properties with the access level of private. However this prevents Proxy classes from retrieving data via **get or. For example the class

class Application*Entity*User {
    /*** @Id @Column(type="integer") @GeneratedValue **/
    private $id;

    public function **set($name, $value) {
        $this->$name = $value;
    }

    public function **get($name) {
        if (property_exists($this, $name)) {
            return $this->$name;
        }

        $trace = debug_backtrace();
        trigger_error(
            'Undefined property via **get(): ' . $name .
            ' in ' . $trace[0]['file'] .
            ' on line ' . $trace[0]['line'],
            E*USER*NOTICE);
        return null;
    }
}

This generates a proxy class that has the following mapping for get:

class class Application*Entity_UserProxy extends \Application_Entity*User implements \Doctrine\ORM\Proxy\Proxy
{
    //..
    public function **get($name)
    {   
        $this->_load();
        return parent::**get($name);
    }

    //..
}

However the call from a proxy class to lets say $image->getUser()->id; will generate the following error:
Undefined property via __get(): id in /var/www/sites/foobar/library/Application/Entity/Proxy/Application_Entity_UserProxy.php on line

This is due to the access declaration in the original class. I filed this as a bug since I know a lot of the documentation has properties of entities defined as private. Changing those declarations to protected alleviates this issue and also does not introduce any security risks or break the OOP access security. With all this being said if I have missed documentation that says please make all entity properties "protected" ignore this and delete.

Originally created by @doctrinebot on GitHub (Nov 18, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user fumanchu182: When creating entities I usually create properties with the access level of private. However this prevents Proxy classes from retrieving data via **get or. For example the class ``` class Application*Entity*User { /*** @Id @Column(type="integer") @GeneratedValue **/ private $id; public function **set($name, $value) { $this->$name = $value; } public function **get($name) { if (property_exists($this, $name)) { return $this->$name; } $trace = debug_backtrace(); trigger_error( 'Undefined property via **get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E*USER*NOTICE); return null; } } ``` This generates a proxy class that has the following mapping for get: ``` class class Application*Entity_UserProxy extends \Application_Entity*User implements \Doctrine\ORM\Proxy\Proxy { //.. public function **get($name) { $this->_load(); return parent::**get($name); } //.. } ``` However the call from a proxy class to lets say $image->getUser()->id; will generate the following error: Undefined property via __get(): id in /var/www/sites/foobar/library/Application/Entity/Proxy/Application_Entity_UserProxy.php on line This is due to the access declaration in the original class. I filed this as a bug since I know a lot of the documentation has properties of entities defined as private. Changing those declarations to protected alleviates this issue and also does not introduce any security risks or break the OOP access security. With all this being said if I have missed documentation that says please make all entity properties "protected" ignore this and delete.
admin added the Bug label 2026-01-22 13:01:54 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1096