From 2c22440cb938e03725d73b3dfe295d7974f40aee Mon Sep 17 00:00:00 2001 From: Dimitar Raev <90788975+draevCS@users.noreply.github.com> Date: Thu, 21 Dec 2023 18:16:43 +0200 Subject: [PATCH] preventing return by reference error in LazyGhostTrait.php this can throws "Only variable references should be returned by reference" when trying to load "metadataFactory" --- LazyGhostTrait.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/LazyGhostTrait.php b/LazyGhostTrait.php index 539cf3e..725c1ba 100644 --- a/LazyGhostTrait.php +++ b/LazyGhostTrait.php @@ -148,7 +148,8 @@ public function &__get($name): mixed } $accessor = Registry::$classAccessors[$scope] ??= Registry::getClassAccessors($scope); - return $accessor['get']($this, $name, null !== $readonlyScope); + $var = $accessor['get']($this, $name, null !== $readonlyScope); + return $var; } catch (\Error $e) { if (\Error::class !== $e::class || !str_starts_with($e->getMessage(), 'Cannot access uninitialized non-nullable property')) { throw $e; @@ -163,7 +164,8 @@ public function &__get($name): mixed $accessor['set']($this, $name, []); - return $accessor['get']($this, $name, null !== $readonlyScope); + $var = $accessor['get']($this, $name, null !== $readonlyScope); + return $var; } catch (\Error) { throw $e; }