-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VarExporter][DoctrineBundle] Accessing unknown properties on lazy ghost objects generates notices instead exceptions #48970
Comments
LazyGhostTrait cannot break the contract of PropertyAccessorInterface because it is not bound by the contract. Anyway, can you please provide a repository with the working reproducer? That'd help a lot. Thanks. |
/cc @javiereguiluz WDYT of my previous comment about easy admin? |
We also run into this if you call This is the backtrace for that error by the way:
|
We are upgrading a site to Symfony 6.3, we were using reflection in one of our classes to access the Connection class of an EntityManager, but now that fails because we do not have the real object and have this uninitialised lazy ghost instead. Any ideas? |
@kiler129 could you please wrap your reproducer into a repository to help me bootstrap this quickly? |
I have a very minimal repo to reproduce this for my case. It comes down to: $p = PropertyAccess::createPropertyAccessor();
$item = new \Proxies\__CG__\App\Entity\Item();
$item->setName('test');
dump($item);
dump($p->isReadable($item, 'name')); // <-- Works
dump($p->isReadable($item, 'missing')); // <-- Gives a notice Repo can be found here. Switching lazy ghost objects off makes this code work without a notice. Let me know if you need anything else from me. My guess is this issue also resolves the original one. |
Should be fixed by #54194 |
…las-grekas) This PR was merged into the 6.4 branch. Discussion ---------- [PropertyAccess] Fix checking for missing properties | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #48970, fix #54194, fix #51919 | License | MIT PropertyAccess and PropertyInfo make a few assumptions when magic methods are involved. Namely they assume that if a `__get` method is defined, then any property name is accessible. This assumption is generally wrong, and this becomes more evident with the introduction of lazy objects. The linked issue gives some more details. In this PR, I tweak these assumptions in order to make less of them. Note that there is no bullet-proof way to decide if a *virtual* property exists in PHP. We're missing an `__exists()` magic method for that. Because of this, I'm submitting this PR to 6.4 and not 5.4. Let 5.4 end its life quietly and ensure 6.4 works at its best with lazy ghosts, where they're mainstream. Commits ------- 9610a7c [PropertyAccess] Fix checking for missing properties
Symfony version(s) affected
6.2.4
Description
Initially this bug looked like an issue with EasyAdmin Bundle, as it is triggered by its code. The simplest way to do it is to add a field which doesn't exist on an entity, e.g.:
When
enable_lazy_ghost_objects
is disabled this works correctly and simply renders an empty field/custom template. However, the issue isn't actually in EAB but inLazyGhostTrait
breaking thePropertyAccessorInterface
promise:symfony/src/Symfony/Component/PropertyAccess/PropertyAccessorInterface.php
Lines 69 to 74 in 991c2ba
->getValue()
should produce an exception when a given property doesn't exist, which EAB relies on: https://github.com/EasyCorp/EasyAdminBundle/blob/4db1860871809ca0be610ba5dab9be26ba165351/src/Field/Configurator/CommonPreConfigurator.php#L49-L53How to reproduce
PoC reproducer, pick your own entity of course. In my case the
type
field is configured as:The test code I used:
With
enable_lazy_ghost_objects=false
:With
enable_lazy_ghost_objects=true
:Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: