<?php
//config as array: easy to write
$configArray = [
    'debug' => true,
    'dsn' => 'mysql://user:pass@host',
];

//config class: nice for static analysis with phpstan
class Config
{
    /**
     * @var bool
     */
    public $debug;
    
    /**
     * @var string
     */
    public $dsn;
}

//cast an array with all data into an object of our Config class
$configObject = unserialize(
    preg_replace(
        '#^O:8:"stdClass":#',
        'O:6:"Config":',
        serialize((object) $configArray)
    )
);
var_dump($configObject);
