Skip to content

Symfony 4.4: Undefined index: http_method #34365

@ostrolucky

Description

@ostrolucky

Doing following in symfony-demo with symfony 4.4@beta deps

Index: src/Controller/SecurityController.php
@@ -12,12 +12,14 @@
 namespace App\Controller;
 
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+use Symfony\Component\HttpClient\HttpClient;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Routing\Annotation\Route;
 use Symfony\Component\Security\Core\Security;
 use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
 use Symfony\Component\Security\Http\Util\TargetPathTrait;
+use Symfony\Contracts\HttpClient\HttpClientInterface;
 
 /**
  * Controller used to manage the application security.
@@ -33,8 +35,9 @@
     /**
      * @Route("/login", name="security_login")
      */
-    public function login(Request $request, Security $security, AuthenticationUtils $helper): Response
+    public function login(Request $request, Security $security, AuthenticationUtils $helper, HttpClientInterface $httpClient): Response
     {
+        $r = $httpClient->request('GET', 'https://jsonplaceholder.typicode.com/todos/1');
         // if user is already logged in, don't display the login page again
         if ($security->isGranted('ROLE_USER')) {
             return $this->redirectToRoute('blog_index');

Causes

Twig\Error\RuntimeError:
An exception has been thrown during the rendering of a template ("Notice: Undefined index: http_method").

  at templates/base.html.twig:119

ErrorException:
Notice: Undefined index: http_method

  at vendor/symfony/http-client/DataCollector/HttpClientDataCollector.php:122
  at Symfony\Component\HttpClient\DataCollector\HttpClientDataCollector->collectOnClient(object(TraceableHttpClient))
     (vendor/symfony/http-client/DataCollector/HttpClientDataCollector.php:44)
  at Symfony\Component\HttpClient\DataCollector\HttpClientDataCollector->collect(object(Request), object(Response), null)
     (vendor/symfony/http-kernel/Profiler/Profiler.php:178)
  at Symfony\Component\HttpKernel\Profiler\Profiler->collect(object(Request), object(Response), null)
     (vendor/symfony/http-kernel/EventListener/ProfilerListener.php:90)

What's intriguing is that removing the $r variable declaration fixes this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions