Breaking: #108113 - Globals _GET and _POST not reset to current Request data anymore
See forge#108113
Description
The frontend and backend application chain roughly splits like this:
- Bootstrap
- Create Request object from globals
- Start application
- Run middleware chain
- Run RequestHandler to create a Response by calling controllers (backend) or
Content(frontend)Object Renderer
There was old compatibility code in
Request
that reset the PHP global variables
_GET,
_POST,
HTTP_ and
HTTP_ to values that may have been
written to their Request object counterparts by middlewares.
This backwards compatibility layer has been removed.
Additionally, in frontend rendering, the global variable
$GLOBALS is no longer populated within the
Prepare
middleware. It is now set later in
Request.
$GLOBALS itself is another compatibility layer that the
TYPO3 Core aims to phase out over time.
Impact
The impact is twofold:
- Some TYPO3 Core middlewares manipulate the Request object's "GET"
parameter list (
$request->get) to, for example, resolve the frontend slug into the page uid. This is itself a backwards compatibility layer. Frontend-related code can no longer expect these manipulated variables to exist in the globalsQuery Params () _GET,_POST,HTTP_andGET_ VARS HTTP_.POST_ VARS - Middlewares that are executed after
Prepare(middleware keyTypo Script Frontend Rendering typo3/) can no longer rely oncms- frontend/ prepare- tsfe- rendering $GLOBALSbeing set.['TYPO3_ REQUEST']
Affected installations
Instances running code that relies on the removed compatibility layers may fail or lead to unexpected results.
Migration
Middlewares receive the Request object directly and should use it instead
of fetching it from
$GLOBALS. Services triggered by
middlewares that rely on the Request should have it passed in explicitly.
One example frequently used in middlewares is
Content:
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
$cor = GeneralUtility::makeInstance(ContentObjectRenderer::class);
$cor->setRequest($request);
$result = $cor->doSomething();
Code should in general never rely on the globals
_GET,
_POST,
HTTP_ and
HTTP_. Request-related
state should always be fetched from the Request object. Note that the helper
method
General will also be phased out once the
TYPO3 Core has removed its last remaining usages.