-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Corece an array
out of an stdClass
?
#436
Labels
Type: Enhancement
Most issues will probably ask for additions or changes.
Comments
Ocramius
added
the
Type: Enhancement
Most issues will probably ask for additions or changes.
label
Jan 12, 2024
This could be a nice addition indeed. Just thinking out loud here: We could accept any <?php
$x = (object) [];
$x->foo = 'bar';
class X {
public $foo = 'bar';
private $baz = 'bar';
}
var_dump((array) $x);
var_dump((array) new X); However: |
IMO a bit too risky 😁 Array casts on objects lead to weird null byte keys too. My endorsement would be to start with Any |
Ocramius
added a commit
to Ocramius/psl
that referenced
this issue
Jan 16, 2024
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.
veewee
pushed a commit
that referenced
this issue
Jan 17, 2024
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just throwing out ideas, but in the context of JSON -> Domain, the
ShapeType
could be useful when dealing with JSON structures where the difference between hashmap and array is sometimes to be preserved:The text was updated successfully, but these errors were encountered: