Skip to content

Conversation

calfc
Copy link
Contributor

@calfc calfc commented Jul 14, 2025

This PR fixes a few minor bugs resulting from the use of inline variable assignment within nullsafe method chains in PendingRequest.php class. When $this->factory is null, the inline assignment never occurs, leading to variable undefined errors.

This PR moves the assignment of these variables outside of the factory call to ensure that they are always defined, regardless of whether $this->factory is null.

@taylorotwell
Copy link
Member

There is no tests to show anything was fixed?

@calfc
Copy link
Contributor Author

calfc commented Jul 14, 2025

There is no tests to show anything was fixed?

Mea culpa! Of course. 🤦 I'll open a new PR with tests if that's ok.

@rodrigopedra
Copy link
Contributor

@taylorotwell, although @calfc is willing to work on a new PR to add tests, one can easily reproduce it:

<?php

use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Artisan;

Artisan::command('local:test', function () {
    $request = new PendingRequest(); // $factory property is null by default

    $this->info($request->get('https://example.invalid/')->body());
});
$ php artisan local:test

   ErrorException 

  Undefined variable $request

  at vendor/laravel/framework/src/Illuminate/Http/Client/PendingRequest.php:1579
    1575▕         $this->factory?->recordRequestResponsePair(
    1576▕             $request = new Request($e->getRequest()), null
    1577▕         );
    1578▕ 
  ➜ 1579▕         $this->dispatchConnectionFailedEvent($request, $exception);
    1580▕ 
    1581▕         throw $exception;
    1582▕     }
    1583▕ 

      +5 vendor frames 

  6   routes/console.php:9
      Illuminate\Http\Client\PendingRequest::get()
      +13 vendor frames 

  20  artisan:16
      Illuminate\Foundation\Application::handleCommand()

@calfc
Copy link
Contributor Author

calfc commented Jul 15, 2025

Hey @rodrigopedra here is the updated PR with tests:

#56292

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