Skip to content

Commit 4ab6c5d

Browse files
committed
do not access properties before initialization
1 parent 335e5dd commit 4ab6c5d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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)