<?php

abstract class Serializer
{
    public function __construct(array $dictionary)
    {
        $class_name = get_class($this);
        $class_vars = get_class_vars($class_name);
        
        foreach ($class_vars as $key => $default)
        {
            $value = array_key_exists($key, $dictionary)
                ? $dictionary[$key]
                : $default;
            
            $this->{$key} = $value;
        }
    }
}

# ===== ===== ===== ===== =====
# program
# ===== ===== ===== ===== =====

final class MySerializer extends Serializer
{
    public string $param_1 = 'hello';
    public string $param_2 = 'world';
}

$parameters = array('param_2' => 'value_1');
$serializer = new MySerializer($parameters);

print_r($serializer);

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: