Fix isHydrated() returning false with typed public properties#33
Open
enlivenapp wants to merge 2 commits intoflightphp:masterfrom
Open
Fix isHydrated() returning false with typed public properties#33enlivenapp wants to merge 2 commits intoflightphp:masterfrom
enlivenapp wants to merge 2 commits intoflightphp:masterfrom
Conversation
b48e22b to
36e76f5
Compare
Contributor
|
This fix might be at odds with your other PR that I just merged. Want to resolve the conflicts and let me know? Thanks! |
When a subclass declares typed public properties (e.g. public int $id), PDO::FETCH_INTO sets them directly, bypassing __set(). This leaves the internal $data array empty, causing isHydrated() to always return false after find() and findAll(). Added syncDeclaredProperties() which detects initialized declared properties and copies them into $data after fetch operations. enlivenapp <mw@enlivenapp.com>
lastInsertId() returns a string, which throws a TypeError when assigned to a typed public int property under strict_types. Cast the value to int when the primary key property has an int type declaration. enlivenapp <mw@enlivenapp.com>
36e76f5 to
ea2b0eb
Compare
Contributor
Author
|
It was indeed. Apologies for the messy PR business. in the attempt to keep things separate so it'd be easier for you to pick what you wanted to use I did too much separation. This is now a 33/34 combo merged together (since 33 needed 34 to work). rebased, etc etc... |
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.
I created a subclass with typed public properties:
After calling
find()on an existing record:I expected
isHydrated()to returntrue, since the property values are populated correctly ($user->namereturns"John").Instead,
isHydrated()returnsfalse. This causes patterns like the following to always return null:Subclasses without typed properties are not affected.
Tests included. All existing tests continue to pass.