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

Skip to content

Commit 4f20ec6

Browse files
[VarExporter] Guard against unset keys in Registry::$states
1 parent f951250 commit 4f20ec6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Symfony/Component/VarExporter/LazyGhostTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public function __serialize(): array
324324

325325
public function __destruct()
326326
{
327-
$state = Registry::$states[$this->lazyObjectId ?? null] ?? null;
327+
$state = Registry::$states[$this->lazyObjectId ?? ''] ?? null;
328328

329329
try {
330330
if ($state && !\in_array($state->status, [LazyObjectState::STATUS_INITIALIZED_FULL, LazyObjectState::STATUS_INITIALIZED_PARTIAL], true)) {

src/Symfony/Component/VarExporter/LazyProxyTrait.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public function &__get($name): mixed
9696
if (null === $scope || isset($propertyScopes["\0$scope\0$name"])) {
9797
if (isset($this->lazyObjectId)) {
9898
if ('lazyObjectReal' === $name && self::class === $scope) {
99-
$this->lazyObjectReal = (Registry::$states[$this->lazyObjectId]->initializer)();
99+
$state = Registry::$states[$this->lazyObjectId] ?? null;
100+
$this->lazyObjectReal = $state ? ($state->initializer)() : null;
100101

101102
return $this->lazyObjectReal;
102103
}
@@ -196,7 +197,9 @@ public function __isset($name): bool
196197
if (null === $scope || isset($propertyScopes["\0$scope\0$name"])) {
197198
if (isset($this->lazyObjectId)) {
198199
if ('lazyObjectReal' === $name && self::class === $scope) {
199-
return null !== $this->lazyObjectReal = (Registry::$states[$this->lazyObjectId]->initializer)();
200+
$state = Registry::$states[$this->lazyObjectId] ?? null;
201+
202+
return null !== $this->lazyObjectReal = $state ? ($state->initializer)() : null;
200203
}
201204
if (isset($this->lazyObjectReal)) {
202205
$instance = $this->lazyObjectReal;

0 commit comments

Comments
 (0)