Last active
October 15, 2015 09:48
-
-
Save Taluu/d100aff845125e91c4b7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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