Created
July 6, 2023 10:31
-
-
Save hungthai1401/508564b9285de52ac105d12aea617878 to your computer and use it in GitHub Desktop.
AnonymousSerialize.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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