kitetail / zttp

A developer-experience focused HTTP client, optimized for most common use cases.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work with older versions of Laravel due to Collection namespace collision

opened this issue · comments

This may be entirely to do with some oddity of the project where I'm trying to switch to Zttp (Lumen v5.1.7, due to requirements back when it was built and lack of time/resources to rework it in 5.5 or full Laravel), but the changes in runBeforeSendingCallbacks in commit 7b6dddc throw an error for me on any request, including a simple get with no parameters:

$response = Zttp::get('https://github.com');

PHP error: Undefined property: Illuminate\Support\Collection::$each in [...]/vendor/kitetail/zttp/src/Zttp.php on line 178

Using kitetail/zttp v0.3.0 and illuminate/support v5.1.41.
Illuminate\Support\Collection definitely has the each function, but I'm probably in over my head as to what I'm doing wrong. If I switch back to array_reduce and [] instead of collect(), there are no errors and the call behaves as expected. Any idea what I'm running up against? Again, fully expecting it to be something on my end (and I'm not expecting help with that) with the older Lumen/Illuminate versions in play rather than a Zttp issue, but I figured I could check.

I bet this is because we use the collect helper function and Lumen already has it defined so we are getting an old version of the Collection class. Not at my computer right now but I'll double check this when I get home 👍🏻

So the issue is unfortunately somewhat complex, I've opened an issue on the package we use with more details:

tighten/collect#54

I'm going to rename this issue to match the root cause and will think if there's a good interim solution.

I ran into this on a pretty blank API project that had laravel/tinker in its dependencies. Tinker apparently installed illuminate/support v 5.2.x when depending on the latest tinker.