PHP code example of qlimix / serializable

1. Go to this page and download the library: Download qlimix/serializable 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/ */

    

qlimix / serializable example snippets




use Qlimix\Serializable\SerializableInterface;

final class FooBar implements SerializableInterface
{
    /** @var string */
    private $foo;
    
    /** @var int */
    private $bar;
    
    public function __construct(string $foo, int $bar)
    {
        $this->foo = $foo;
        $this->bar = $bar;
    }
    
    public function getName(): string
    {
        return 'foo.bar';
    }
    
    public function serialize(): array
    {
        return [
            'foo' => $this->foo,
            'bar' => $this->bar,
        ];
    }

    public static function deserialize(array $data): SerializableInterface
    {
        return new self($data['foo'], $data['bar']);
    }
}