PHP exposes a number of so-called global variables which contain information about the HTTP request, such as $_POST
, $_GET
, $_FILES
, $_SESSION
, etc. The Request
class contains a static createFromGlobals()
method in order to instantiate a request object based on these variables:
use Symfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();
When using the Symfony framework, you should not instantiate the request object yourself. Instead, you should use the object that is instantiated when the framework is bootstrapped in app.php
/ app_dev.php
. For instance by type hinting the request object in your controller.