diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index eab0576bc539..0220d5d7801e 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -2602,7 +2602,7 @@ public function escapeWhenCastingToString($escape = true) * * @return array */ - public function __sleep() + public function __serialize() { $this->mergeAttributesFromCachedCasts(); @@ -2611,7 +2611,7 @@ public function __sleep() $this->relationAutoloadCallback = null; $this->relationAutoloadContext = null; - return array_keys(get_object_vars($this)); + return get_object_vars($this); } /** @@ -2619,8 +2619,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->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'); }