-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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.8] Fix isset if not array or ArrayAccess #29860
Conversation
Co-authored-by: Dries Vints <[email protected]>
This feels hard to read. What are you trying to check? |
Why did we stop using array_key_exists in the first place? Was it a PHP 7.4 reason? |
I haven't wrapped my head around the change yet, but I can confirm that upgrading from 5.8.34 to 5.8.35 broke because of this change (which this PR fixes, at least for me) |
In what situation is I feel like we need to better understand this issue and not just throw code against the wall hoping that is sticks. |
Its See this comment
If your resource doesn't implement ArrayAccess, you now get an error. |
How does yours not implement ArrayAccess? Are you extending the built-in Laravel resource stuff? |
where To be fair, the items are not Eloquent models, but it worked just fine. |
Can someone post an entire stack trace so we can see where this is even being called from and get a better idea of the overall use case? |
There are a couple of cases where the Resource is instantiated with a non array, non ArrayAccess object |
@matthewnessworthy Like? Where? When? How? We need more details. |
Where does the |
I misspoke - The stack trace looks like:
|
It's a LengthAwarePaginator of plain PHP objects? No Eloquent stuff, etc? |
That's right, they are not Eloquent models. |
Hmm, OK. We may have to add this to the upgrade guide that all underlying objects of resources should implement ArrayAccess. I think patching around that may hide other problems. |
@jasonlbeggs can you post the code of that object? |
For Laravel 5.8, at least, we shouldn't break code. |
@driesvints, I think you meant to tag @jasonvarga? |
I spoke to Dries outside of this thread, and landed on if you're not putting actual Resource objects in there, it was basically being misused. If it was working, it was a coincidence. Might apply to @matthewnessworthy 's issue too. |
@jasonlbeggs yes, sorry! @jasonvarga yeah exactly. All resource objects should extend the @GrahamCampbell @taylorotwell I think in this case this PR can be closed. |
The phpdoc should be changed from |
@GrahamCampbell no. It's the property that needs to be an instance of JsonResource. Not |
Yeh, exactly. That property has type documented as |
@GrahamCampbell ah yeah. Feel free to send in a PR 👍 |
Hmmm, why would someone construct a JsonResource with a JsonResource? |
@GrahamCampbell resources' collections work a little weird and are needed for this I think |
Heh. Maybe a note in the docs is sufficient. |
I believe that the result obtained when using Query Builder should be a class that implements ArrayAccess and not a stdClass, since not everyone uses Paginator from a Model Eloquent. It is for this reason that it also throws an error when using Resources. |
No description provided.