PHP code example of adagio / serializer
1. Go to this page and download the library: Download adagio/serializer library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adagio / serializer example snippets
use Adagio\Serializer\DumbSerializer;
class Foo
{
private $myProperty = 123;
/**
* @var Bar
*/
public $bar;
}
class Bar
{
private $word1 = 'Hello';
protected $word2 = ['world!'];
}
$foo = new Foo;
$foo->bar = new Bar;
$serializer = new DumbSerializer;
echo $json = $serializer->serialize($foo));
// Outputs:
// {
// "myProperty": 123,
// "bar": {
// "word1": "Hello",
// "word2": [
// "world!"
// ]
// }
// }
print_r($serializer->deserialize($json));
// Outputs:
// stdClass Object
// (
// [myProperty] => 123
// [bar] => Array
// (
// [word1] => Hello
// [word2] => Array
// (
// [0] => world!
// )
//
// )
//
// )
print_r($serializer->deserialize($json, Foo::class));
// Outputs:
// Foo Object
// (
// [myProperty] => 123
// [bar] => Array
// (
// [word1] => Hello
// [word2] => Array
// (
// [0] => world!
// )
//
// )
//
// )