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

[5.4] Higher Order Array or Object Bug Fix #16274

Merged
merged 4 commits into from
Nov 6, 2016
Merged

[5.4] Higher Order Array or Object Bug Fix #16274

merged 4 commits into from
Nov 6, 2016

Conversation

alexbowers
Copy link
Contributor

No description provided.

@alexbowers alexbowers changed the title Hotfix/higher order array or object [5.4] Higher Order Array or Object Bug Fix Nov 5, 2016
@taylorotwell
Copy link
Member

Personally I would suggest just checking for is_array. It will be much faster than data_get in this situation.

@alexbowers
Copy link
Contributor Author

Feel free to modify as you see fit.

I assume you mean to do return is_array($value) ? $value[$key] : $value->{$key}; ?

@taylorotwell
Copy link
Member

yes.

@alexbowers
Copy link
Contributor Author

@taylorotwell This change has been made.

@taylorotwell taylorotwell merged commit 6c38ec5 into laravel:master Nov 6, 2016
@franzliedke
Copy link
Contributor

I highly advise against this. There's already enough magic involved.

If you're dealing with arrays, accessing them should work like this:

$collection->map['field']

We can do this by implementing offsetGet on the proxy class. I'll send a PR.

@alexbowers
Copy link
Contributor Author

I'm happy for this to be altered if it improves the code / expectations of the code; however I would say a common API is preferential to it throwing an error if you try to access the collection as shown in the examples, and it happens to be an array.

Offtopic: @franzliedke I have sent you a message on larachat, if you get the chance to check it out, i'd be grateful :)

@franzliedke
Copy link
Contributor

Collection items don't just happen to be arrays, though. You should know what you're dealing with when you are accessing a whole collection through the proxy.

That's the point of this feature: accessing all items in a collection just like you would access one object, which you can do because they all have the same type/interface. I want this to be as expectable as possible.

I've seen your message, I will get to it. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants