Skip to content

Instantly share code, notes, and snippets.

@alOneh
Created March 7, 2019 17:03
Show Gist options
  • Save alOneh/a2d63f3c0c2f52d084842136d56bd9a2 to your computer and use it in GitHub Desktop.
Save alOneh/a2d63f3c0c2f52d084842136d56bd9a2 to your computer and use it in GitHub Desktop.
How to serialize User information in session
<?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