<?php

abstract class JsonDeserializer
{
    /**
     * @param string|array $json
     * @return $this
     */
    public static function Deserialize($json)
    {
        $className = get_called_class();
        $classInstance = new $className();
        if (is_string($json))
            $json = json_decode($json);
        foreach ($json as $key => $value)
            $classInstance->{$key} = $value;
        return $classInstance;
    }
    /**
     * @param string $json
     * @return $this[]
     */
    public static function DeserializeArray($json)
    {
        $json = json_decode($json);
        $items = [];
        foreach ($json as $item)
            $items[] = self::Deserialize($item);
        return $items;
    }
}

class MyObject extends JsonDeserializer
{
    /** @var string */
    public $property1;
    
    /** @var string */
    public $property2;
    
    /** @var string */
    public $property3;
    
    /** @var string */
    public $array1;
}

$objectInstance = new MyObject();
$objectInstance->property1 = 'Value 1';
$objectInstance->property2 = 'Value 2';
$objectInstance->property3 = 'Value 3';
$objectInstance->array1 = ['Key 1' => 'Value 1', 'Key 2' => 'Value 2'];
var_dump($objectInstance);

$jsonSerialized = json_encode($objectInstance);
var_dump($jsonSerialized);

$deserializedInstance = MyObject::Deserialize($jsonSerialized);
var_dump($deserializedInstance);