Fix handling of unmapped properties in proxy objects#2698
Merged
alcaeus merged 1 commit intodoctrine:2.9.xfrom Nov 18, 2024
Merged
Fix handling of unmapped properties in proxy objects#2698alcaeus merged 1 commit intodoctrine:2.9.xfrom
alcaeus merged 1 commit intodoctrine:2.9.xfrom
Conversation
a8186c0 to
a8500a7
Compare
GromNaN
approved these changes
Nov 15, 2024
malarzm
approved these changes
Nov 16, 2024
This was referenced Nov 18, 2024
Contributor
|
Sorry about necroposting, but after upgrading to 2.11 recently, I think we have stumbled onto this and it's causing a "bug" in our code. I used quotes because I am not sure if our observed behavior is a bug or works-as-intended. Our simplified scenario:
class Document
{
private int $mappedProperty;
private ServiceInterface $unmappedProperty;
public function getUnmappedProperty()
{
$this->mappedProperty; // Dummy call to get proxy to initialize
return $this->unmappedProperty;
}
/**
* Called from a listener on Events::postLoad
*/
public function initialize(ServiceInterface $service)
{
$this->unmappedProperty = $service;
}
}Is this expected? Is our (admittedly awkward) scenario unsupported? Or should I open an issue with this? |
This was referenced Nov 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
While working on a project that contained unmapped hooked properties, I realised that proxies try to unset these hooked properties, despite them not even being mapped properties. Note that this doesn't mean ODM supports hooked properties - it just removes an edge case where you can't use hooked properties at all, even when they aren't mapped and thus shouldn't be handled by ODM at all.
To work around this issue, when creating a proxy we now also skip all properties of the class that aren't mapped, leaving them set and not triggering initialisation when they are accessed.