Skip to content

Instantly share code, notes, and snippets.

@hungthai1401
Created July 6, 2023 10:31
Show Gist options
  • Save hungthai1401/508564b9285de52ac105d12aea617878 to your computer and use it in GitHub Desktop.
Save hungthai1401/508564b9285de52ac105d12aea617878 to your computer and use it in GitHub Desktop.
AnonymousSerialize.php
<?php
trait AnonymousSerialize
{
public function serialize()
{
$properties = [];
foreach(get_object_vars($this) as $name => $value) {
$properties[$name] = $value;
}
return serialize($properties);
}
public function unserialize($data)
{
foreach(unserialize($data) as $name => $value) {
$this->{$name} = $value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment