Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,28 @@ public function escapeWhenCastingToString($escape = true)
return $this;
}

/**
* Get the properties for serialization.
*
* @return array
*/
protected function getPropertiesForSerialization(): array
{
if (version_compare(PHP_VERSION, '8.4.0', '<')) {
return array_keys(get_object_vars($this));
}

$keys = [];

foreach ((new ReflectionClass($this))->getProperties() as $property) {
if (!$property->isStatic() && !$property->hasHooks()) {
$keys[] = $property->getName();
}
}

return $keys;
}

/**
* Prepare the object for serialization.
*
Expand All @@ -2595,17 +2617,7 @@ public function __sleep()
$this->relationAutoloadCallback = null;
$this->relationAutoloadContext = null;

$keys = get_object_vars($this);

if (version_compare(PHP_VERSION, '8.4.0', '>=')) {
foreach ((new ReflectionClass($this))->getProperties() as $property) {
if ($property->hasHooks()) {
unset($keys[$property->getName()]);
}
}
}

return array_keys($keys);
return $this->getPropertiesForSerialization();
}

/**
Expand Down