Proxy generator dumps incorrect default value for enums into lazy properties defaults #6901

Closed
opened 2026-01-22 15:41:00 +01:00 by admin · 4 comments
Owner

Originally created by @mbabker on GitHub (Jan 12, 2022).

Originally assigned to: @kimhemsoe on GitHub.

Bug Report

Q A
BC Break no
Version 2.11.0

Summary

When updating an app to ORM 2.11 and changing an existing string field to use enums, when the field has a default value, the proxy is incorrectly generated and results in errors similar to "ReflectionException: Class "App\Entity\Card\App\Suit" does not exist." This is because the proxy class doesn't have the leading slash to make it a FQCN, so it's treated as a relative namespace when accessed later.

Current behavior

The proxy class' $lazyPropertiesDefaults array dumps defaults with a class name that's not fully qualified, resulting in a value that's perceived as a relative namespace path.

How to reproduce

Expected behavior

The $lazyPropertiesDefaults array should use fully qualified class names to avoid class not found errors, or if it cannot support enums with lazy loading, the proxy generator skips the field.

As a temporary workaround, I can move these default assignments to the class constructor.

Originally created by @mbabker on GitHub (Jan 12, 2022). Originally assigned to: @kimhemsoe on GitHub. ### Bug Report | Q | A |------------ | ------ | BC Break | no | Version | 2.11.0 #### Summary When updating an app to ORM 2.11 and changing an existing string field to use enums, when the field has a default value, the proxy is incorrectly generated and results in errors similar to "ReflectionException: Class "App\Entity\Card\App\Suit" does not exist." This is because the proxy class doesn't have the leading slash to make it a FQCN, so it's treated as a relative namespace when accessed later. #### Current behavior The proxy class' `$lazyPropertiesDefaults` array dumps defaults with a class name that's not fully qualified, resulting in a value that's perceived as a relative namespace path. #### How to reproduce - Clone https://github.com/mbabker/proxy-generator-bug - Run `composer install` - Run `vendor/bin/doctrine orm:generate-proxies` - Inspect the generated proxy in the `proxies` folder #### Expected behavior The `$lazyPropertiesDefaults` array should use fully qualified class names to avoid class not found errors, or if it cannot support enums with lazy loading, the proxy generator skips the field. As a temporary workaround, I can move these default assignments to the class constructor.
admin added the Bug label 2026-01-22 15:41:00 +01:00
admin closed this issue 2026-01-22 15:41:00 +01:00
Author
Owner

@derrabus commented on GitHub (Jan 12, 2022):

Thank you. Would you be able to work on a bugfix?

@derrabus commented on GitHub (Jan 12, 2022): Thank you. Would you be able to work on a bugfix?
Author
Owner

@mbabker commented on GitHub (Jan 13, 2022):

Doubtful, anything meaningful is going to require more engine knowledge than I have.

I can monkey-patch the ProxyGenerator so it doesn't consider enums as a lazy-loadable property:

diff --git a/lib/Doctrine/Common/Proxy/ProxyGenerator.php b/lib/Doctrine/Common/Proxy/ProxyGenerator.php
index f71cb915..29e0de4a 100644
--- a/lib/Doctrine/Common/Proxy/ProxyGenerator.php
+++ b/lib/Doctrine/Common/Proxy/ProxyGenerator.php
@@ -980,6 +980,12 @@ EOT;
                 continue;
             }
 
+            if (function_exists('enum_exists')) {
+                if (!$property->getType()->isBuiltin() && enum_exists($property->getType()->getName())) {
+                    continue;
+                }
+            }
+
             $properties[] = $name;
         }
 

But, getting it to actually support enums is where my skills end. The issue looks to be in how var_export() exports things and I don't have the engine or regex knowledge to be able to mess with that output and get it to fix things.

@mbabker commented on GitHub (Jan 13, 2022): Doubtful, anything meaningful is going to require more engine knowledge than I have. I can monkey-patch the ProxyGenerator so it doesn't consider enums as a lazy-loadable property: ```diff diff --git a/lib/Doctrine/Common/Proxy/ProxyGenerator.php b/lib/Doctrine/Common/Proxy/ProxyGenerator.php index f71cb915..29e0de4a 100644 --- a/lib/Doctrine/Common/Proxy/ProxyGenerator.php +++ b/lib/Doctrine/Common/Proxy/ProxyGenerator.php @@ -980,6 +980,12 @@ EOT; continue; } + if (function_exists('enum_exists')) { + if (!$property->getType()->isBuiltin() && enum_exists($property->getType()->getName())) { + continue; + } + } + $properties[] = $name; } ``` But, getting it to actually support enums is where my skills end. The issue looks to be in how `var_export()` exports things and I don't have the engine or regex knowledge to be able to mess with that output and get it to fix things.
Author
Owner

@kimhemsoe commented on GitHub (Jan 13, 2022):

Can confirm that the issue is with var_export. Ex:

<?php

namespace Proxies;

class AProxy {
    public static $lazyPropertiesDefaults = array (
  'suit' => 
  App\Suit::Hearts,
);
}

Simplified version of what ProxyGenerator is generation

Possible solution could prefix with preg_replace()

@kimhemsoe commented on GitHub (Jan 13, 2022): Can confirm that the issue is with var_export. Ex: ``` <?php namespace Proxies; class AProxy { public static $lazyPropertiesDefaults = array ( 'suit' => App\Suit::Hearts, ); } ``` Simplified version of what ProxyGenerator is generation Possible solution could prefix with preg_replace()
Author
Owner

@beberlei commented on GitHub (Feb 2, 2022):

Please upgrade to doctrine/common 3.2.2 to fix this issue in your projects.

@beberlei commented on GitHub (Feb 2, 2022): Please upgrade to doctrine/common 3.2.2 to fix this issue in your projects.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6901