From 57c3f9439bcd22b47058229cb85c7b5b4598c8c3 Mon Sep 17 00:00:00 2001 From: Arshid Date: Fri, 12 Sep 2025 07:32:17 +0530 Subject: [PATCH 1/2] Replace __wakeup with __unserialize for object unserialization Replace __wakeup with __unserialize for object unserialization Replace __wakeup with __unserialize for object unserialization Replace __wakeup with __unserialize for object unserialization --- src/Illuminate/Database/Eloquent/Model.php | 15 ++++++++++----- src/Illuminate/Queue/Middleware/RateLimited.php | 13 +++++++++---- .../Queue/Middleware/RateLimitedWithRedis.php | 9 +++++++-- .../Integration/Cache/Fixtures/Unserializable.php | 2 +- tests/Integration/Queue/CallQueuedHandlerTest.php | 4 ++-- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index eab0576bc539..05e128849951 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -2601,8 +2601,8 @@ public function escapeWhenCastingToString($escape = true) * Prepare the object for serialization. * * @return array - */ - public function __sleep() + */ + public function __serialize() { $this->mergeAttributesFromCachedCasts(); @@ -2611,16 +2611,21 @@ public function __sleep() $this->relationAutoloadCallback = null; $this->relationAutoloadContext = null; - return array_keys(get_object_vars($this)); + return get_object_vars($this); } /** * When a model is being unserialized, check if it needs to be booted. * * @return void - */ - public function __wakeup() + */ + public function __unserialize($data) { + foreach ($data as $property => $value) { + if (property_exists($this, $property)) { + $this->{$property} = $value; + } + } $this->bootIfNotBooted(); $this->initializeTraits(); diff --git a/src/Illuminate/Queue/Middleware/RateLimited.php b/src/Illuminate/Queue/Middleware/RateLimited.php index a2b5343e59db..9320bd0780de 100644 --- a/src/Illuminate/Queue/Middleware/RateLimited.php +++ b/src/Illuminate/Queue/Middleware/RateLimited.php @@ -147,11 +147,11 @@ protected function getTimeUntilNextRetry($key) * * @return array */ - public function __sleep() + public function __serialize() { return [ - 'limiterName', - 'shouldRelease', + 'limiterName' => $this->limiterName, + 'shouldRelease' => $this->shouldRelease, ]; } @@ -160,8 +160,13 @@ public function __sleep() * * @return void */ - public function __wakeup() + public function __unserialize($data) { + foreach ($data as $property => $value) { + if (property_exists($this, $property)) { + $this->{$property} = $value; + } + } $this->limiter = Container::getInstance()->make(RateLimiter::class); } } diff --git a/src/Illuminate/Queue/Middleware/RateLimitedWithRedis.php b/src/Illuminate/Queue/Middleware/RateLimitedWithRedis.php index 25870e08f034..3769ce45123b 100644 --- a/src/Illuminate/Queue/Middleware/RateLimitedWithRedis.php +++ b/src/Illuminate/Queue/Middleware/RateLimitedWithRedis.php @@ -93,9 +93,14 @@ protected function getTimeUntilNextRetry($key) * * @return void */ - public function __wakeup() + public function __unserialize($data) { - parent::__wakeup(); + foreach ($data as $property => $value) { + if (property_exists($this, $property)) { + $this->{$property} = $value; + } + } + parent::__unserialize($data); $this->redis = Container::getInstance()->make(Redis::class); } diff --git a/tests/Integration/Cache/Fixtures/Unserializable.php b/tests/Integration/Cache/Fixtures/Unserializable.php index 4deefdaeb6f2..83730e758fc4 100644 --- a/tests/Integration/Cache/Fixtures/Unserializable.php +++ b/tests/Integration/Cache/Fixtures/Unserializable.php @@ -6,7 +6,7 @@ class Unserializable { - public function __sleep() + public function __serialize() { throw new Exception('Not serializable'); } diff --git a/tests/Integration/Queue/CallQueuedHandlerTest.php b/tests/Integration/Queue/CallQueuedHandlerTest.php index b97d8d530a58..21f4770818d3 100644 --- a/tests/Integration/Queue/CallQueuedHandlerTest.php +++ b/tests/Integration/Queue/CallQueuedHandlerTest.php @@ -195,7 +195,7 @@ public function handle() // } - public function __wakeup() + public function __unserialize($data) { throw new ModelNotFoundException('Foo'); } @@ -209,7 +209,7 @@ public function handle() // } - public function __wakeup() + public function __unserialize($data) { throw new ModelNotFoundException('Foo'); } From 4b747a6585d2d7528ab90a21d2be5e34e2550146 Mon Sep 17 00:00:00 2001 From: Arshid Date: Fri, 12 Sep 2025 07:47:40 +0530 Subject: [PATCH 2/2] Replace __wakeup with __unserialize for object unserialization --- src/Illuminate/Database/Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 05e128849951..0220d5d7801e 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -2601,7 +2601,7 @@ public function escapeWhenCastingToString($escape = true) * Prepare the object for serialization. * * @return array - */ + */ public function __serialize() { $this->mergeAttributesFromCachedCasts(); @@ -2618,7 +2618,7 @@ public function __serialize() * When a model is being unserialized, check if it needs to be booted. * * @return void - */ + */ public function __unserialize($data) { foreach ($data as $property => $value) {