[3.4.0] TypeError from ProxyFactory::__construct() when using native lazy objects #7520

Closed
opened 2026-01-22 15:52:53 +01:00 by admin · 8 comments
Owner

Originally created by @eisnstein on GitHub (Jun 16, 2025).

Bug Report

Q A
Version 3.4.0
PHP 8.4.8

Summary

When using the new native lazy objects, I get an TypeError in the EntityManager constructor, when it tries to create a ProxyFactory. $proxyDir and $proxyNs need to be strings, but because those are not set, nulls are given.

My workaround is to set empty strings:

$config->enableNativeLazyObjects(true);
$config->setProxyDir('');
$config->setProxyNamespace('');

PHP Version: 8.4.8

Stack Trace:

TypeError thrown with message "Doctrine\ORM\Proxy\ProxyFactory::__construct(): Argument #2 ($proxyDir) must be of type string, null given, called in /app/vendor/doctrine/orm/src/EntityManager.php on line 137"

Stacktrace:
#3 TypeError in /app/vendor/doctrine/orm/src/Proxy/ProxyFactory.php:144
#2 Doctrine\ORM\Proxy\ProxyFactory:__construct in /app/vendor/doctrine/orm/src/EntityManager.php:137
#1 Doctrine\ORM\EntityManager:__construct in /app/src/Helpers/Database/Database.php:47
#0 Enterprise\Helpers\Database\Database:init in /app/public/index.php:44
Originally created by @eisnstein on GitHub (Jun 16, 2025). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |-------------------------------------------- | ------ | Version | 3.4.0 | PHP | 8.4.8 #### Summary When using the new native lazy objects, I get an TypeError in the EntityManager constructor, when it tries to create a ProxyFactory. $proxyDir and $proxyNs need to be strings, but because those are not set, nulls are given. My workaround is to set empty strings: ```php $config->enableNativeLazyObjects(true); $config->setProxyDir(''); $config->setProxyNamespace(''); ``` PHP Version: 8.4.8 Stack Trace: ``` TypeError thrown with message "Doctrine\ORM\Proxy\ProxyFactory::__construct(): Argument #2 ($proxyDir) must be of type string, null given, called in /app/vendor/doctrine/orm/src/EntityManager.php on line 137" Stacktrace: #3 TypeError in /app/vendor/doctrine/orm/src/Proxy/ProxyFactory.php:144 #2 Doctrine\ORM\Proxy\ProxyFactory:__construct in /app/vendor/doctrine/orm/src/EntityManager.php:137 #1 Doctrine\ORM\EntityManager:__construct in /app/src/Helpers/Database/Database.php:47 #0 Enterprise\Helpers\Database\Database:init in /app/public/index.php:44 ```
admin closed this issue 2026-01-22 15:52:54 +01:00
Author
Owner

@greg0ire commented on GitHub (Jun 16, 2025):

Can you please provide a stack trace?

@greg0ire commented on GitHub (Jun 16, 2025): Can you please provide a [stack trace](https://symfony.com/doc/current/contributing/code/stack_trace.html#getting-stack-traces-with-symfony)?
Author
Owner

@eisnstein commented on GitHub (Jun 17, 2025):

@greg0ire added stack trace

@eisnstein commented on GitHub (Jun 17, 2025): @greg0ire added stack trace
Author
Owner

@greg0ire commented on GitHub (Jun 17, 2025):

Oh OK, I see… may I ask why you are not using ORMSetup, as described in https://www.doctrine-project.org/projects/doctrine-orm/en/3.4/reference/configuration.html#obtaining-an-entitymanager ?

@greg0ire commented on GitHub (Jun 17, 2025): Oh OK, I see… may I ask why you are not using `ORMSetup`, as described in https://www.doctrine-project.org/projects/doctrine-orm/en/3.4/reference/configuration.html#obtaining-an-entitymanager ?
Author
Owner

@eisnstein commented on GitHub (Jun 17, 2025):

@greg0ire I still had the setup from the advanced configuration: https://www.doctrine-project.org/projects/doctrine-orm/en/3.4/reference/advanced-configuration.html

But thanks, I changed it to the ORMSetup and that works.

@eisnstein commented on GitHub (Jun 17, 2025): @greg0ire I still had the setup from the advanced configuration: https://www.doctrine-project.org/projects/doctrine-orm/en/3.4/reference/advanced-configuration.html But thanks, I changed it to the ORMSetup and that works.
Author
Owner

@greg0ire commented on GitHub (Jun 17, 2025):

Right, let's keep this issue opened then.

@greg0ire commented on GitHub (Jun 17, 2025): Right, let's keep this issue opened then.
Author
Owner

@greg0ire commented on GitHub (Jun 17, 2025):

I think it would be OK to relax the type declarations here, since there are checks for both arguments: ab89517093/src/Proxy/ProxyFactory.php (L150-L156)

@greg0ire commented on GitHub (Jun 17, 2025): I think it would be OK to relax the type declarations here, since there are checks for both arguments: https://github.com/doctrine/orm/blob/ab89517093f6d8b08291dfcdc8cbf32c504f5374/src/Proxy/ProxyFactory.php#L150-L156
Author
Owner

@greg0ire commented on GitHub (Jun 17, 2025):

@eisnstein may I ask why it worked before you migrate to native lazy objects? Did you explicitly provide a proxy dir and proxy namespace, or did something else do it for you?

@greg0ire commented on GitHub (Jun 17, 2025): @eisnstein may I ask why it worked before you migrate to native lazy objects? Did you explicitly provide a proxy dir and proxy namespace, or did something else do it for you?
Author
Owner

@eisnstein commented on GitHub (Jun 17, 2025):

@greg0ire exactly, I explicitly set the proxy dir and namespace.

@eisnstein commented on GitHub (Jun 17, 2025): @greg0ire exactly, I explicitly set the proxy dir and namespace.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7520