Created
March 7, 2019 17:03
-
-
Save alOneh/a2d63f3c0c2f52d084842136d56bd9a2 to your computer and use it in GitHub Desktop.
How to serialize User information in session
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 | |
class User implements UserInterface, \Serializable | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function serialize(): string | |
{ | |
return serialize([$this->id, $this->username, $this->password]); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function unserialize($serialized): void | |
{ | |
[$this->id, $this->username, $this->password] = unserialize($serialized, ['allowed_classes' => false]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment