Proxy returns default value without initializing #5379

Open
opened 2026-01-22 15:05:58 +01:00 by admin · 0 comments
Owner

Originally created by @Wilt on GitHub (Jan 12, 2017).

If we define a default value like this:

<?php
/**
 * @Entity
 */
class MyEntity {
    /**
     * @var string
     *
     * @Column(name="myColumn", type="string", length="50")
     */
    private $myColumn = 'myDefaultValue';
    ...
}

And we have a Proxy of MyEntity instead of an initialized entity then pulling the proxy method returns a default value without initializing the entity and resolving the actual database value.

This means that the database value for myColumn is actually holding a completely different value we got returned from our proxy without us realizing this.

Since this way of defining default values is also mentioned in the documentation chapter: 3.2.2. How can I add default values to a column? we were very surprised that this issue occurred.

Are we doing something wrong here? Or is this a bug?

Originally created by @Wilt on GitHub (Jan 12, 2017). If we define a default value like this: <?php /** * @Entity */ class MyEntity { /** * @var string * * @Column(name="myColumn", type="string", length="50") */ private $myColumn = 'myDefaultValue'; ... } And we have a Proxy of `MyEntity` instead of an initialized entity then pulling the proxy method returns a default value without initializing the entity and resolving the actual database value. This means that the database value for `myColumn` is actually holding a completely different value we got returned from our proxy without us realizing this. Since this way of defining default values is also mentioned [in the documentation chapter: **3.2.2. How can I add default values to a column?**](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/faq.html#how-can-i-add-default-values-to-a-column) we were very surprised that this issue occurred. Are we doing something wrong here? Or is this a bug?
admin added the BugMissing Tests labels 2026-01-22 15:05:58 +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#5379