Skip to content

Commit b5e9003

Browse files
Exclude property hooks on return of Model::__sleep() (#57557)
* Exclude property hooks on return of Model::__sleep() * Exclude property hooks on return of Model::__sleep() * Exclude property hooks on return of Model::__sleep() * Exclude property hooks on return of Model::__sleep() * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent fb9dae5 commit b5e9003

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2595,7 +2595,17 @@ public function __sleep()
25952595
$this->relationAutoloadCallback = null;
25962596
$this->relationAutoloadContext = null;
25972597

2598-
return array_keys(get_object_vars($this));
2598+
$keys = get_object_vars($this);
2599+
2600+
if (version_compare(PHP_VERSION, '8.4.0') >= 0) {
2601+
foreach ((new ReflectionClass($this))->getProperties() as $property) {
2602+
if ($property->hasHooks()) {
2603+
unset($keys[$property->getName()]);
2604+
}
2605+
}
2606+
}
2607+
2608+
return array_keys($keys);
25992609
}
26002610

26012611
/**

0 commit comments

Comments
 (0)