-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[12.x] Introduce Arr::from() #55715
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
[12.x] Introduce Arr::from() #55715
Conversation
…instances as scalars
Why? |
I decided to distinguish between "casting to array" and "wrapping in array". I wanted to keep it simple without creating special case for enums where it should not belong (issue with enum was inability to adequately wrap it in array). |
You did! Thanks a lot |
This PR is a second attempt at extracting
getArrayableItems()
functionality into separate function (first PR).Key differences from previous PR are:
Arr::from()
won't wrap scalar values to follow single responsibility principle;getArrayableItems
- see [8.x] Handle collection creation around a single enum #42839);WeakMap
instances are now convertable into lists (keys cannot be preserved for obvious reasons);Arr::arrayable()
helper function has been added to be used in pair withArr:from()
when needed.As for
WeakMap
concern:I am convinced that this issue valid for both collections and arrays - arrays cannot be created with objects as a keys.
We can handle this situation by throwing an exception (current behavior) or by omitting
WeakMap
keys during casting to array (this PR).Let me know if you prefer to keep current behavior.