Comments (18)
It's normal practice to bypass the constructor invocation in Hydration (same as Doctrine).
I'm planning to seriously take a look at this issue during following few weeks.
from orm.
Released https://github.com/Ocramius/GeneratedHydrator/releases/tag/3.1.0, if you wanna give it a spin.
It still uses an old zendframework/zend-hydrator
version for now. I would suggest sending upstream patches to laminas-hydrator
meanwhile.
from orm.
Yes, you might need to report in Zend/Hydrator. Also, check ocramius/generated-hydrator
, it is viable alternative (and it works faster). I think PHP7.4 issues were fixed by @Ocramius
This is the example https://github.com/adrianmiu/forked-php-orm-benchmark/blob/master/cycleorm/CycleOrmTestSuiteWithGeneratedMapper.php
Since Zend is kinda dead we might need to switch to Laminas on a later date. In general, hydration/extraction code has nothing to do with the rest of ORM so it's very easy to change the implementation.
from orm.
I really hope it's not going to end with our own hydration/extraction implementation (hi @vvval). So far it seems that there needs a way to quickly detect if the property has been initialized. I wonder if isset
is working.
from orm.
Yes: of your identifier doesn't exist until after persistence, it is to be null
, and the entity mutable.
Otherwise you just left a landmine there, for somebody else to uncover.
EDIT: s/nullable/mutable
from orm.
@alexndr-novikov can you comment? I know we are widely using 7.4, not sure is it the same issue we solved earlier or something new.
@armpogart thank you for the report.
from orm.
@wolfy-j Actually the issue is not directly in this repo, but the dependency you use. You run following code which itself uses Zend Hydrator and there the following line raises the issue.
It's due to the fact that php 7.4 property value can't be accessed even with reflection if it is not initialized, but the fix is rather easy as ReflectionProperty
class has new methods for that and I see better fix than Doctrine one.
The problem is I don't see how to apply the fix to this repo as it is in direct dependency. Do I need to report there?
And the second problem is the fix will raise minimum php requirements to 7.4, or can we just do some method_exists
check to see if we are on php 7.4 and only do the checks there?
from orm.
Issue on ocramius/generated-hydrator
for reference. Will open an issue on laminas/laminas-hydrator
(since zend is already depracated and repo is archived) and update here.
from orm.
@wolfy-j Are you following discussion on both repos where I referenced this issue?
Do you agree with the statement that it is implementation problem? (there are comments on that on both cases, though I don't agree with them).
from orm.
Not really, if I want to get values from the entity - I have to get values from the entity. If they won't fix it on the library level we will have to write our own hydration/extractor with extra check if the property has been initialized and skip its extraction (orm will be fine with that). But I can't express how much I do not want to write another hydration library.
from orm.
Not only zend-hydrator
fails to work with typed properties, its ReflectionHydrator
somehow ignores the default constructor (so there's no way to safely bypass the exception without making all of the properties nullable).
from orm.
Well, according to Marco comment Ocramius/GeneratedHydrator#124 this canβt be fixed as there design bug.
I can only propose not to declare auto incremental ids in entities at all or stick to uuid or make them nullable.
from orm.
Going to add it to PHP 7.4 specific documentation article. Thank you, Marco.
from orm.
@wolfy-j If I understood correctly, you agree that if not nullable typed property is not initialized that's a design issue. While I agree on the case of identifier (PK) can be nullable until after persistence it is set. What about FK keys which can be also null after persistence (when nulls are allowed), how they would be differentiated?
So also my comment on laminas issue tracker.
from orm.
If the association is nullable, why isn't it mapped as such in the entity?
from orm.
@Ocramius Ok, for making an example simpler.
Suppose we have some content
field in db that can be null. When using typed properties it would be logical to have it null
by default (same goes for any FK that can be null), but how we will differentiate whether it is null by default or it is set to null on purpose (after ORM read operation)?
Now, I'm little bit lost. I need to think more about this...
from orm.
Why there should be a difference? In theory, your code should know nothing about ORM (since we are not talking about AR) so your code should operate relying only on itself.
from orm.
It doesn't even need to be null
by default: if an association is nullable, it can be hydrated as null
when the association isn't set.
from orm.
Related Issues (20)
- π PHP 8.3
- CTE support for QueryBuilder HOT 1
- π fkAction/fkOnDelete has no effect for automatically created migrations HOT 1
- π‘ Add options set for auto-generated column values
- Cascade Persist Fails without cloning object in softDelete Method
- π‘ Cycle schema hydration is too slow
- π HasOne. select by relation property generates unnecessary INNER JOIN HOT 3
- Expected parameter of type 'Cycle\Annotated\Locator\EmbeddingLocatorInterface', 'Spiral\Tokenizer\ClassLocator' provided HOT 2
- Check useless `order by` on some ORM prefetches
- Index Names Not Applied to Database When Using Annotations HOT 1
- π‘ Embeddable Behaviors
- π‘ Allow setting enum cases as property defaults
- π In changelog version 2.8 is missed
- π‘ Ability to use `with` more than once with same relation. For several JOINs HOT 1
- π Issue with Enum Field Difference Detected During Database Migration Synchronization
- π‘ Efficient bulk-loading of morph relations
- π Self transation cannot be resolved. HOT 4
- Duplicate entry for primary key π HOT 4
- π‘ Add documentation for migration generation / drivers HOT 1
- π‘ Scope Classes for Relation Attributes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orm.