diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index ef88a8a1d83e0f8496558914b40e2a18f4b4005e..8c0c656d4e8e1266857b15db7c8860a6d817a6ff 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -102,9 +102,15 @@ class GeneralUtility * * @param string $var GET/POST var to return * @return mixed POST var named $var, if not set, the GET var of the same name and if also not set, NULL. + * @deprecated since TYPO3 v12.3. will be removed in TYPO3 v13.0. */ public static function _GP($var) { + trigger_error( + 'GeneralUtility::_GP() will be removed in TYPO3 v13.0, retrieve request related' . + ' details from PSR-7 ServerRequestInterface instead.', + E_USER_DEPRECATED + ); if (empty($var)) { return; } @@ -145,8 +151,6 @@ class GeneralUtility * * @param string $var Optional pointer to value in GET array (basically name of GET var) * @return mixed If $var is set it returns the value of $_GET[$var]. If $var is NULL (default), returns $_GET itself. - * @see _POST() - * @see _GP() */ public static function _GET($var = null) { @@ -165,8 +169,6 @@ class GeneralUtility * * @param string $var Optional pointer to value in POST array (basically name of POST var) * @return mixed If $var is set it returns the value of $_POST[$var]. If $var is NULL (default), returns $_POST itself. - * @see _GET() - * @see _GP() * @deprecated since TYPO3 v12.2. will be removed in TYPO3 v13.0. */ public static function _POST($var = null) diff --git a/typo3/sysext/core/Documentation/Changelog/12.3/Deprecation-100053-GeneralUtility_GP.rst b/typo3/sysext/core/Documentation/Changelog/12.3/Deprecation-100053-GeneralUtility_GP.rst new file mode 100644 index 0000000000000000000000000000000000000000..1124fc0a63e7cd28f4d30885e7b12d1906062982 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/12.3/Deprecation-100053-GeneralUtility_GP.rst @@ -0,0 +1,67 @@ +.. include:: /Includes.rst.txt + +.. _deprecation-100053-1677670333: + +============================================ +Deprecation: #100053 - GeneralUtility::_GP() +============================================ + +See :issue:`100053` + +Description +=========== + +The method :php:`\TYPO3\CMS\Backend\Utility\GeneralUtility::_GP()` has +been marked as deprecated and should not be used any longer. + +Modern code should access GET and POST data from the PSR-7 :php:`ServerRequestInterface`, +and should avoid accessing superglobals :php:`$_GET` and :php:`$_POST` +directly. This also avoids future side-effects when using sub-requests. Some +:php:`GeneralUtility` related helper methods like :php:`_GP()` violate this, +using them is considered a technical debt. They are being phased out. + + +Impact +====== + +Calling the method from PHP code will log a PHP deprecation level entry, +the method will be removed with TYPO3 v13. + + +Affected installations +====================== + +TYPO3 installations with third-party extensions using :php:`GeneralUtility::_GP()` +are affected. This typically occurs in TYPO3 installations which +have been migrated to latest TYPO3 Core versions and +haven't been adapted properly yet. + +The extension scanner will find usages with a strong match. + + +Migration +========= + +:php:`GeneralUtility::_GP()` is a helper method that retrieves +incoming HTTP `GET` query arguments and `POST` body parameters and returns the value. + +The same result can be achieved by retrieving arguments from the request object. +An instance of the PSR-7 :php:`ServerRequestInterface` is handed over to +controllers by TYPO3 Core's PSR-15 :php:`\TYPO3\CMS\Core\Http\RequestHandlerInterface` +and middleware implementations, and is available in various related scopes +like the frontend :php:`\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer`. + +Typical code: + +.. code-block:: php + + use TYPO3\CMS\Backend\Utility\GeneralUtility; + + // Before + $value = GeneralUtility::_GP('tx_scheduler'); + + // After + $value = $request->getParsedBody()['tx_scheduler']) ?? $request->getQueryParams()['tx_scheduler']) ?? null; + + +.. index:: PHP-API, FullyScanned, ext:core diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php index 396afbc5a64b071c0153c630f879ace6119bfb4f..c2688b98a57f0f7b3cada60c807eb967a2f64faf 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php @@ -96,42 +96,6 @@ class GeneralUtilityTest extends UnitTestCase return $path; } - /////////////////////////// - // Tests concerning _GP - /////////////////////////// - /** - * @test - * @dataProvider gpDataProvider - */ - public function canRetrieveValueWithGP($key, $get, $post, $expected): void - { - $_GET = $get; - $_POST = $post; - self::assertSame($expected, GeneralUtility::_GP($key)); - } - - /** - * Data provider for canRetrieveValueWithGP. - * All test values also check whether slashes are stripped properly. - */ - public function gpDataProvider(): array - { - return [ - 'No key parameter' => [null, [], [], null], - 'Key not found' => ['cake', [], [], null], - 'Value only in GET' => ['cake', ['cake' => 'li\\e'], [], 'li\\e'], - 'Value only in POST' => ['cake', [], ['cake' => 'l\\ie'], 'l\\ie'], - 'Value from POST preferred over GET' => ['cake', ['cake' => 'is a'], ['cake' => '\\lie'], '\\lie'], - 'Value can be an array' => [ - 'cake', - ['cake' => ['is a' => 'l\\ie']], - [], - ['is a' => 'l\\ie'], - ], - 'Empty-ish key' => ['0', ['0' => 'zero'], ['0' => 'zero'], null], - ]; - } - //////////////////////// // Tests concerning _GET //////////////////////// diff --git a/typo3/sysext/core/Tests/UnitDeprecated/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/UnitDeprecated/Utility/GeneralUtilityTest.php index 907fa04976b07e3498061d1bcaa41a54afbb2b3d..e5d09f5b6c17a1bf572e49b2a8b1f7833eb2b23d 100644 --- a/typo3/sysext/core/Tests/UnitDeprecated/Utility/GeneralUtilityTest.php +++ b/typo3/sysext/core/Tests/UnitDeprecated/Utility/GeneralUtilityTest.php @@ -75,4 +75,33 @@ class GeneralUtilityTest extends UnitTestCase $_POST = $post; self::assertSame($expected, GeneralUtility::_POST($key)); } + + public function gpDataProvider(): array + { + return [ + 'No key parameter' => [null, [], [], null], + 'Key not found' => ['cake', [], [], null], + 'Value only in GET' => ['cake', ['cake' => 'li\\e'], [], 'li\\e'], + 'Value only in POST' => ['cake', [], ['cake' => 'l\\ie'], 'l\\ie'], + 'Value from POST preferred over GET' => ['cake', ['cake' => 'is a'], ['cake' => '\\lie'], '\\lie'], + 'Value can be an array' => [ + 'cake', + ['cake' => ['is a' => 'l\\ie']], + [], + ['is a' => 'l\\ie'], + ], + 'Empty-ish key' => ['0', ['0' => 'zero'], ['0' => 'zero'], null], + ]; + } + + /** + * @test + * @dataProvider gpDataProvider + */ + public function canRetrieveValueWithGP($key, $get, $post, $expected): void + { + $_GET = $get; + $_POST = $post; + self::assertSame($expected, GeneralUtility::_GP($key)); + } } diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php index 79e77fc202465aa04b37b3d2c0d225450adf837b..843f7f23dedd0c728cab5bdab86041872abcfe5f 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php @@ -1464,4 +1464,11 @@ return [ 'Deprecation-99633-GeneralUtilityPOST.rst', ], ], + 'TYPO3\CMS\Core\Utility\GeneralUtility::_GP' => [ + 'numberOfMandatoryArguments' => 1, + 'maximumNumberOfArguments' => 1, + 'restFiles' => [ + 'Deprecation-100053-GeneralUtility_GP.rst', + ], + ], ];