Skip to content

Commit 74b4bbd

Browse files
committed
bug #51904 [HttpFoundation] do not access properties before initialization (xabbuh)
This PR was merged into the 7.0 branch. Discussion ---------- [HttpFoundation] do not access properties before initialization | Q | A | ------------- | --- | Branch? | 7.0 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT Commits ------- 6e19d1a do not access properties before initialization
2 parents 71f226a + 6e19d1a commit 74b4bbd

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ class Request
152152
protected string $defaultLocale = 'en';
153153

154154
/**
155-
* @var array<string, string[]>
155+
* @var array<string, string[]>|null
156156
*/
157-
protected static array $formats;
157+
protected static ?array $formats = null;
158158

159159
protected static ?\Closure $requestFactory = null;
160160

@@ -1499,7 +1499,11 @@ public function isNoCache(): bool
14991499
*/
15001500
public function getPreferredFormat(?string $default = 'html'): ?string
15011501
{
1502-
if ($this->preferredFormat ??= $this->getRequestFormat(null)) {
1502+
if (!isset($this->preferredFormat) && null !== $preferredFormat = $this->getRequestFormat(null)) {
1503+
$this->preferredFormat = $preferredFormat;
1504+
}
1505+
1506+
if ($this->preferredFormat ?? null) {
15031507
return $this->preferredFormat;
15041508
}
15051509

0 commit comments

Comments
 (0)