Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a88c7fa

Browse files
committed
bug #40964 [HttpFoundation] Fixes for PHP 8.1 deprecations (jrmajor)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpFoundation] Fixes for PHP 8.1 deprecations | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Fixes passing `null` to non-nullable arguments. Commits ------- 10be072 [HttpFoundation] Fixes for PHP 8.1 deprecations
2 parents b306bdb + 10be072 commit a88c7fa

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public static function createFromGlobals()
292292
{
293293
$request = self::createRequestFromFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER);
294294

295-
if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded')
295+
if (0 === strpos($request->headers->get('CONTENT_TYPE', ''), 'application/x-www-form-urlencoded')
296296
&& \in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])
297297
) {
298298
parse_str($request->getContent(), $data);
@@ -1391,7 +1391,7 @@ public function setRequestFormat($format)
13911391
*/
13921392
public function getContentType()
13931393
{
1394-
return $this->getFormat($this->headers->get('CONTENT_TYPE'));
1394+
return $this->getFormat($this->headers->get('CONTENT_TYPE', ''));
13951395
}
13961396

13971397
/**
@@ -1564,7 +1564,7 @@ public function getContent($asResource = false)
15641564
*/
15651565
public function getETags()
15661566
{
1567-
return preg_split('/\s*,\s*/', $this->headers->get('if_none_match'), -1, \PREG_SPLIT_NO_EMPTY);
1567+
return preg_split('/\s*,\s*/', $this->headers->get('if_none_match', ''), -1, \PREG_SPLIT_NO_EMPTY);
15681568
}
15691569

15701570
/**
@@ -1790,13 +1790,13 @@ protected function prepareRequestUri()
17901790
*/
17911791
protected function prepareBaseUrl()
17921792
{
1793-
$filename = basename($this->server->get('SCRIPT_FILENAME'));
1793+
$filename = basename($this->server->get('SCRIPT_FILENAME', ''));
17941794

1795-
if (basename($this->server->get('SCRIPT_NAME')) === $filename) {
1795+
if (basename($this->server->get('SCRIPT_NAME', '')) === $filename) {
17961796
$baseUrl = $this->server->get('SCRIPT_NAME');
1797-
} elseif (basename($this->server->get('PHP_SELF')) === $filename) {
1797+
} elseif (basename($this->server->get('PHP_SELF', '')) === $filename) {
17981798
$baseUrl = $this->server->get('PHP_SELF');
1799-
} elseif (basename($this->server->get('ORIG_SCRIPT_NAME')) === $filename) {
1799+
} elseif (basename($this->server->get('ORIG_SCRIPT_NAME', '')) === $filename) {
18001800
$baseUrl = $this->server->get('ORIG_SCRIPT_NAME'); // 1and1 shared hosting compatibility
18011801
} else {
18021802
// Backtrack up the script_filename to find the portion matching
@@ -1836,7 +1836,7 @@ protected function prepareBaseUrl()
18361836
$truncatedRequestUri = substr($requestUri, 0, $pos);
18371837
}
18381838

1839-
$basename = basename($baseUrl);
1839+
$basename = basename($baseUrl ?? '');
18401840
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
18411841
// no match whatsoever; set it blank
18421842
return '';
@@ -1987,7 +1987,7 @@ private static function createRequestFromFactory(array $query = [], array $reque
19871987
*/
19881988
public function isFromTrustedProxy()
19891989
{
1990-
return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies);
1990+
return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR', ''), self::$trustedProxies);
19911991
}
19921992

19931993
private function getTrustedValues(int $type, string $ip = null): array

src/Symfony/Component/HttpFoundation/Tests/Fixtures/response-functional/cookie_raw_urlencode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
$r->headers->setCookie(new Cookie($str, $str, 0, '/', null, false, false, true, null));
1010
$r->sendHeaders();
1111

12-
setrawcookie($str, $str, 0, '/', null, false, false);
12+
setrawcookie($str, $str, 0, '/', '', false, false);

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public function testGetFormatFromMimeType($format, $mimeTypes)
446446
public function getFormatToMimeTypeMapProviderWithAdditionalNullFormat()
447447
{
448448
return array_merge(
449-
[[null, [null, 'unexistent-mime-type']]],
449+
[[null, ['unexistent-mime-type']]],
450450
$this->getFormatToMimeTypeMapProvider()
451451
);
452452
}

0 commit comments

Comments
 (0)