From 36fdbd4c6a35d689384eebd4c33477a6b444d883 Mon Sep 17 00:00:00 2001 From: Dmytro Kulyk Date: Fri, 24 Jul 2020 23:39:26 +0300 Subject: [PATCH] [6.x] Prevent to serialize uninitialized properties (#33644) * Prevent to serialize uninitialized properties * Updated test for unitialized properties --- src/Illuminate/Queue/SerializesModels.php | 6 ++++++ tests/Integration/Queue/typed-properties.php | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/Illuminate/Queue/SerializesModels.php b/src/Illuminate/Queue/SerializesModels.php index e96111628ff7..52c0f405d831 100644 --- a/src/Illuminate/Queue/SerializesModels.php +++ b/src/Illuminate/Queue/SerializesModels.php @@ -65,6 +65,12 @@ public function __serialize() continue; } + $property->setAccessible(true); + + if (! $property->isInitialized($this)) { + continue; + } + $name = $property->getName(); if ($property->isPrivate()) { diff --git a/tests/Integration/Queue/typed-properties.php b/tests/Integration/Queue/typed-properties.php index 17f655ab5f82..ba4666c9d3c9 100644 --- a/tests/Integration/Queue/typed-properties.php +++ b/tests/Integration/Queue/typed-properties.php @@ -11,6 +11,8 @@ class TypedPropertyTestClass public ModelSerializationTestUser $user; + public ModelSerializationTestUser $unitializedUser; + protected int $id; private array $names;