Skip to content
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

Added support for coercing stdClass to array<TKey, TValue> #437

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

Ocramius
Copy link
Contributor

Fixes #436

This change is useful when decoding JSON hashmaps into PHP hashmaps, since PHP keeps JSON-decoded data as an stdClass unless explicitly told to do so.

Also note that preserving JSON structures as stdClass is sometimes very much required, since an empty hashmap is a lossy conversion to [] performed by json_decode(), when using associative: true. This patch makes preserving JSON data structures a bit easier.

This adds some very minimal overhead to ShapeType#coerce(), which should be imperceptible.

Fixes azjezz#436

This change is useful when decoding JSON hashmaps into PHP hashmaps, since PHP keeps
JSON-decoded data as an `stdClass` unless explicitly told to do so.

Also note that preserving JSON structures as `stdClass` is sometimes very much required,
since an empty hashmap is a lossy conversion to `[]` performed by `json_decode()`, when
using `associative: true`. This patch makes preserving JSON data structures a bit easier.

This adds some very minimal overhead to `ShapeType#coerce()`, which should be imperceptible.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 7544565365

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 99.013%

Totals Coverage Status
Change from base Build 7355812555: 0.001%
Covered Lines: 4213
Relevant Lines: 4255

💛 - Coveralls

@veewee veewee added Priority: Low This issue can probably be picked up by anyone looking to contribute to the project, as an entry fix Status: Accepted It's clear what the subject of the issue is about, and what the resolution should be. Type: Enhancement Most issues will probably ask for additions or changes. labels Jan 16, 2024
src/Psl/Type/Internal/ShapeType.php Show resolved Hide resolved
@veewee veewee added this to the 2.10.0 milestone Jan 17, 2024
@veewee veewee merged commit 8a4e77b into azjezz:next Jan 17, 2024
14 checks passed
@veewee
Copy link
Collaborator

veewee commented Jan 17, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Low This issue can probably be picked up by anyone looking to contribute to the project, as an entry fix Status: Accepted It's clear what the subject of the issue is about, and what the resolution should be. Type: Enhancement Most issues will probably ask for additions or changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Corece an array out of an stdClass?
3 participants