Skip to content

Commit 1dcdb66

Browse files
committed
bug #51812 [HttpFoundation] Fix type of properties in Request class (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- [HttpFoundation] Fix type of properties in Request class | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #51792 | License | MIT Partially reverts #51121 where I didn't consider the behavior change reported in the linked issue. Commits ------- 18e3c75 [HttpFoundation] Fix type of properties in Request class
2 parents 8d8acf1 + 18e3c75 commit 1dcdb66

File tree

3 files changed

+53
-46
lines changed

3 files changed

+53
-46
lines changed

src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020
*/
2121
class TreeBuilder implements NodeParentInterface
2222
{
23+
/**
24+
* @var NodeInterface|null
25+
*/
2326
protected $tree;
27+
28+
/**
29+
* @var NodeDefinition
30+
*/
2431
protected $root;
2532

2633
public function __construct(string $name, string $type = 'array', NodeBuilder $builder = null)
@@ -53,7 +60,7 @@ public function buildTree(): NodeInterface
5360
public function setPathSeparator(string $separator)
5461
{
5562
// unset last built as changing path separator changes all nodes
56-
unset($this->tree);
63+
$this->tree = null;
5764

5865
$this->root->setPathSeparator($separator);
5966
}

src/Symfony/Component/HttpClient/Response/MockResponse.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class MockResponse implements ResponseInterface, StreamableInterface
2828
use CommonResponseTrait;
2929
use TransportResponseTrait;
3030

31-
private string|iterable $body;
31+
private string|iterable|null $body;
3232
private array $requestOptions = [];
3333
private string $requestUrl;
3434
private string $requestMethod;
@@ -98,7 +98,7 @@ public function cancel(): void
9898
$this->info['canceled'] = true;
9999
$this->info['error'] = 'Response has been canceled.';
100100
try {
101-
unset($this->body);
101+
$this->body = null;
102102
} catch (TransportException $e) {
103103
// ignore errors when canceling
104104
}
@@ -172,7 +172,7 @@ protected static function perform(ClientState $multi, array &$responses): void
172172
foreach ($responses as $response) {
173173
$id = $response->id;
174174

175-
if (!isset($response->body)) {
175+
if (null === $response->body) {
176176
// Canceled response
177177
$response->body = [];
178178
} elseif ([] === $response->body) {

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -136,57 +136,57 @@ class Request
136136
protected $content;
137137

138138
/**
139-
* @var string[]
139+
* @var string[]|null
140140
*/
141141
protected $languages;
142142

143143
/**
144-
* @var string[]
144+
* @var string[]|null
145145
*/
146146
protected $charsets;
147147

148148
/**
149-
* @var string[]
149+
* @var string[]|null
150150
*/
151151
protected $encodings;
152152

153153
/**
154-
* @var string[]
154+
* @var string[]|null
155155
*/
156156
protected $acceptableContentTypes;
157157

158158
/**
159-
* @var string
159+
* @var string|null
160160
*/
161161
protected $pathInfo;
162162

163163
/**
164-
* @var string
164+
* @var string|null
165165
*/
166166
protected $requestUri;
167167

168168
/**
169-
* @var string
169+
* @var string|null
170170
*/
171171
protected $baseUrl;
172172

173173
/**
174-
* @var string
174+
* @var string|null
175175
*/
176176
protected $basePath;
177177

178178
/**
179-
* @var string
179+
* @var string|null
180180
*/
181181
protected $method;
182182

183183
/**
184-
* @var string
184+
* @var string|null
185185
*/
186186
protected $format;
187187

188188
/**
189-
* @var SessionInterface|callable(): SessionInterface
189+
* @var SessionInterface|callable():SessionInterface|null
190190
*/
191191
protected $session;
192192

@@ -282,16 +282,16 @@ public function initialize(array $query = [], array $request = [], array $attrib
282282
$this->headers = new HeaderBag($this->server->getHeaders());
283283

284284
$this->content = $content;
285-
unset($this->languages);
286-
unset($this->charsets);
287-
unset($this->encodings);
288-
unset($this->acceptableContentTypes);
289-
unset($this->pathInfo);
290-
unset($this->requestUri);
291-
unset($this->baseUrl);
292-
unset($this->basePath);
293-
unset($this->method);
294-
unset($this->format);
285+
$this->languages = null;
286+
$this->charsets = null;
287+
$this->encodings = null;
288+
$this->acceptableContentTypes = null;
289+
$this->pathInfo = null;
290+
$this->requestUri = null;
291+
$this->baseUrl = null;
292+
$this->basePath = null;
293+
$this->method = null;
294+
$this->format = null;
295295
}
296296

297297
/**
@@ -468,16 +468,16 @@ public function duplicate(array $query = null, array $request = null, array $att
468468
$dup->server = new ServerBag($server);
469469
$dup->headers = new HeaderBag($dup->server->getHeaders());
470470
}
471-
unset($dup->languages);
472-
unset($dup->charsets);
473-
unset($dup->encodings);
474-
unset($dup->acceptableContentTypes);
475-
unset($dup->pathInfo);
476-
unset($dup->requestUri);
477-
unset($dup->baseUrl);
478-
unset($dup->basePath);
479-
unset($dup->method);
480-
unset($dup->format);
471+
$dup->languages = null;
472+
$dup->charsets = null;
473+
$dup->encodings = null;
474+
$dup->acceptableContentTypes = null;
475+
$dup->pathInfo = null;
476+
$dup->requestUri = null;
477+
$dup->baseUrl = null;
478+
$dup->basePath = null;
479+
$dup->method = null;
480+
$dup->format = null;
481481

482482
if (!$dup->get('_format') && $this->get('_format')) {
483483
$dup->attributes->set('_format', $this->get('_format'));
@@ -1182,7 +1182,7 @@ public function getHost(): string
11821182
*/
11831183
public function setMethod(string $method)
11841184
{
1185-
unset($this->method);
1185+
$this->method = null;
11861186
$this->server->set('REQUEST_METHOD', $method);
11871187
}
11881188

@@ -1201,7 +1201,7 @@ public function setMethod(string $method)
12011201
*/
12021202
public function getMethod(): string
12031203
{
1204-
if (isset($this->method)) {
1204+
if (null !== $this->method) {
12051205
return $this->method;
12061206
}
12071207

@@ -1249,7 +1249,7 @@ public function getRealMethod(): string
12491249
*/
12501250
public function getMimeType(string $format): ?string
12511251
{
1252-
if (!isset(static::$formats)) {
1252+
if (null === static::$formats) {
12531253
static::initializeFormats();
12541254
}
12551255

@@ -1263,7 +1263,7 @@ public function getMimeType(string $format): ?string
12631263
*/
12641264
public static function getMimeTypes(string $format): array
12651265
{
1266-
if (!isset(static::$formats)) {
1266+
if (null === static::$formats) {
12671267
static::initializeFormats();
12681268
}
12691269

@@ -1280,7 +1280,7 @@ public function getFormat(?string $mimeType): ?string
12801280
$canonicalMimeType = trim(substr($mimeType, 0, $pos));
12811281
}
12821282

1283-
if (!isset(static::$formats)) {
1283+
if (null === static::$formats) {
12841284
static::initializeFormats();
12851285
}
12861286

@@ -1305,7 +1305,7 @@ public function getFormat(?string $mimeType): ?string
13051305
*/
13061306
public function setFormat(?string $format, string|array $mimeTypes)
13071307
{
1308-
if (!isset(static::$formats)) {
1308+
if (null === static::$formats) {
13091309
static::initializeFormats();
13101310
}
13111311

@@ -1586,13 +1586,13 @@ public function isNoCache(): bool
15861586
*/
15871587
public function getPreferredFormat(?string $default = 'html'): ?string
15881588
{
1589-
if (isset($this->preferredFormat) || null !== $preferredFormat = $this->getRequestFormat(null)) {
1590-
return $this->preferredFormat ??= $preferredFormat;
1589+
if ($this->preferredFormat ??= $this->getRequestFormat(null)) {
1590+
return $this->preferredFormat;
15911591
}
15921592

15931593
foreach ($this->getAcceptableContentTypes() as $mimeType) {
1594-
if ($preferredFormat = $this->getFormat($mimeType)) {
1595-
return $this->preferredFormat = $preferredFormat;
1594+
if ($this->preferredFormat = $this->getFormat($mimeType)) {
1595+
return $this->preferredFormat;
15961596
}
15971597
}
15981598

@@ -1639,7 +1639,7 @@ public function getPreferredLanguage(array $locales = null): ?string
16391639
*/
16401640
public function getLanguages(): array
16411641
{
1642-
if (isset($this->languages)) {
1642+
if (null !== $this->languages) {
16431643
return $this->languages;
16441644
}
16451645

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy