title: Symfony login form — Fatal error: Call to a member function get() on null
body: <p>I'm trying to load some method (which creates a login form for me) from one source controller into another one.</p>
  
  <p>Here is my source SecurityController:</p>
  
  <pre><code>namespace ImmoBundle\Controller\Security;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\HttpFoundation\Request;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use ImmoBundle\Entity\User;
  use ImmoBundle\Form\Type\LoginType;
  
  class SecurityController extends Controller
  {
      /**
       * @Route("/login", name="login")
       */
      public function loginAction(Request $request)
      {
          $parametersArray = $this-&gt;loadForm($request);
  
          return $this-&gt;render(
              'ImmoBundle::Security/login.html.twig',
              array(
                  'login_form' =&gt; $parametersArray['form']-&gt;createView(),
                  'error'      =&gt; $parametersArray['error'],
                  'last_email' =&gt; $parametersArray['lastEmail'],
              )
          );
      }
  
  
      public function loadForm($request)
      {
          $user = new User();
          $form = $this-&gt;createForm(LoginType::class, $user);
          $form-&gt;handleRequest($request);
          $authenticationUtils = $this-&gt;get('security.authentication_utils');
          $error = $authenticationUtils-&gt;getLastAuthenticationError();
  
          $lastEmail = $authenticationUtils-&gt;getLastUsername();
          $parametersArray['form'] = $form;
          $parametersArray['error'] = $error;
          $parametersArray['lastEmail'] = $lastEmail;
  
          return $parametersArray;
      }
  }
  </code></pre>
  
  <p>Then I've defined my source controller as a Service in services.yml:</p>
  
  <pre><code>login_form_service:
      class: ImmoBundle\Controller\Security\SecurityController
  </code></pre>
  
  <p>My target controller looks like this:</p>
  
  <pre><code>namespace ImmoBundle\Controller\Pages;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Symfony\Component\HttpFoundation\Response;
  use Symfony\Component\HttpFoundation\Request;
  
  class ListingPageController extends Controller
  {
      /**
       * @Route("/id/{listingId}", name="idPage", requirements={
       *     "listingId": "\d+"
       * })
       */
      public function loadIdAction($listingId, Request $request)
      {
          $yourController = $this-&gt;get('login_form_service');
  
          print_r($yourController-&gt;loadForm($request));
  
          return $this-&gt;render(
              'ImmoBundle::page.html.twig',
              array()
          );
      }
  }
  </code></pre>
  
  <p>But instead of an object in line  </p>
  
  <blockquote>
    <p>print_r($yourController->loadForm($request))</p>
  </blockquote>
  
  <p>I've got this error: <code>Fatal error: Call to a member function get() on null</code> </p>
  
  <p>What am I doing wrong?</p>