Skip to content

Instantly share code, notes, and snippets.

@Taluu
Last active October 15, 2015 09:48
Show Gist options
  • Save Taluu/d100aff845125e91c4b7 to your computer and use it in GitHub Desktop.
Save Taluu/d100aff845125e91c4b7 to your computer and use it in GitHub Desktop.
<?php
class Foo implements Serializable
{
public $foo, $bar;
public function serialize()
{
return json_encode(['foo' => $this->foo, 'bar' => $this->bar]);
}
public function unserialize($data)
{
$data = json_decode($data, true);
$this->foo = $data['foo'];
$this->bar = $data['bar'];
}
}
$foo = new Foo;
$foo->foo = ['bar' => 'baz'];
$foo->bar = 'baz';
var_dump($foo, $s = serialize($foo), unserialize($s));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment