mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
bug in readonly properties & native lazy objects, triggers immedtiately #7552
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @beberlei on GitHub (Sep 15, 2025).
Just found another bug with the readonly IDs and new PHP 8.4 ghost objects - if the ID is readonly of a related entity - when it tries to create a proxy for that related entity - the proxy is immediately initialized from the ReadonlyAccessor - it calls the reflection property->isInitialized on the ID and this triggers the initialization in the foreach right after the proxy generation. Here is the stacktrace from inside of the ghost object function to visualize which flow triggered the initialization.
This cascades to a very ugly and hard to trace bug - it sets the
originalEntityDatato empty array, which then behind the scenes ignores all changes made on that entity on flush. Just spent like 3 hours debugging to find that out. Also couldn't use debugger to trace that issue, because the xdebug itself triggers the initialization of entities so manual logs until my head spins..Originally posted by @vuryss in https://github.com/doctrine/doctrine-website/pull/479#issuecomment-3292973817
@vuryss commented on GitHub (Sep 15, 2025):
Sorry I wanna correct the line numbers, because of my manual log entries they have been shifted.
The line numbers are as follows:
2ca63df90c/src/Proxy/ProxyFactory.php (L211)2ca63df90c/src/Mapping/PropertyAccessors/ReadonlyAccessor.php (L29)2ca63df90c/src/Proxy/ProxyFactory.php (L227)2ca63df90c/src/UnitOfWork.php (L2539)2ca63df90c/src/Internal/Hydration/SimpleObjectHydrator.php (L176)@adrav commented on GitHub (Jan 1, 2026):
Maybe related: https://github.com/doctrine/orm/issues/12334
@greg0ire commented on GitHub (Jan 4, 2026):
@adrav @vuryss I've asked my LLM, it's suggesting this fix in
src/Mapping/PropertyAccessors/ReadonlyAccessor.php:I think it is fine because if
$objectis an initialized lazy object, then I think callingsetValue()is always fine. Can you please test it and let me know if it does address the issue?@greg0ire commented on GitHub (Jan 4, 2026):
But maybe this is going to be fixed at the PHP level: https://github.com/php/php-src/pull/20831
@greg0ire commented on GitHub (Jan 6, 2026):
Todo: consider the fix described in https://github.com/php/php-src/issues/20830#issuecomment-3714381830
@greg0ire commented on GitHub (Jan 6, 2026):
The fix my LLM suggested above is probably bad because
I will try to reproduce it and fix it.
EDIT: oh but
$this->parent->setValue()should result in8cbd34c666/src/Mapping/PropertyAccessors/RawValuePropertyAccessor.php (L42), so this is probably fine.@greg0ire commented on GitHub (Jan 6, 2026):
If somebody here could please test https://github.com/doctrine/orm/pull/12335 on their application, that would be great.
@adrav commented on GitHub (Jan 9, 2026):
I have just tested it with my code described here: https://github.com/doctrine/orm/issues/12334
It works fine with the fix: https://github.com/doctrine/orm/pull/12335.