comphp/config-php provides CommonPHP\Drivers\Config\PHP\PhpConfigurationDriver for PHP configuration files that return arrays.
use CommonPHP\Drivers\Config\PHP\PhpConfigurationDriver;
$driver = new PhpConfigurationDriver();
$config = [
'name' => 'demo',
'database' => [
'host' => 'localhost',
],
];
$data = $driver->encode($config);
$decoded = $driver->decode($data);$driver->write(__DIR__ . '/config.php', $config);
$config = $driver->read(__DIR__ . '/config.php');PHP config files are trusted code. Decoding and reading include and execute PHP, and the result must be an array.
Failures throw CommonPHP config exceptions instead of returning false.