This feels like a very intrusive way. Zend Framework offers a way to manually parse the application.ini into an object and make the object editable. Then you can overwrite the defaults from application.ini in PHP code. Please see the following copy and paste example from our old PHP based site. It used to be in index.php directly before bootstrapping the application.

~~~php
// manually load application.ini and overwrite
// respective values from creds.json
$config_ini = new Zend_Config_Ini(
	APPLICATION_PATH . '/configs/application.ini',
	APPLICATION_ENV,
	array('allowModifications' => true)
);

$creds = array();
if (isset($_ENV['CRED_FILE'])) {
	# read the credentials file
	$string = file_get_contents($_ENV['CRED_FILE'], false);
	if ($string == false) {
    	die('FATAL: Could not read credentials file');
	}
	# the file contains a JSON string, decode it and return an associative array
	$creds = json_decode($string, true);
}

// MySQL
if (array_key_exists('MYSQLD', $creds)) {
	$db_creds = array(
		"dbname" => $creds['MYSQLD']['MYSQLD_DATABASE'],
        "host" => $creds['MYSQLD']['MYSQLD_HOST'],
        "username" => $creds['MYSQLD']['MYSQLD_USER'],
		"password" => $creds['MYSQLD']['MYSQLD_PASSWORD']
	);
} elseif (array_key_exists('MYSQLS', $creds)) {
	$db_creds = array(
		"dbname" => $creds['MYSQLS']['MYSQLS_DATABASE'],
        "host" => $creds['MYSQLS']['MYSQLS_HOSTNAME'],
        "username" => $creds['MYSQLS']['MYSQLS_USERNAME'],
		"password" => $creds['MYSQLS']['MYSQLS_PASSWORD']
	);
} else {
	if (APPLICATION_ENV != 'development') {
		die('FATAL: No MYSQLS or MYSQLD Add-on found.');
	}
}
if ($db_creds){
	foreach ($db_creds as $key => $value) {
		$config_ini->resources->db->params->__set($key, $value);
	}
}

// Memcache
if (array_key_exists('MEMCACHIER', $creds)) {
	$config_ini->resources->cachemanager->memcached->backend->options
		->servers->one->__set('host', $creds['MEMCACHIER']['MEMCACHIER_SERVERS']);
	$config_ini->resources->cachemanager->memcached->backend->options
		->__set('username', $creds['MEMCACHIER']['MEMCACHIER_USERNAME']);
	$config_ini->resources->cachemanager->memcached->backend->options
		->__set('password', $creds['MEMCACHIER']['MEMCACHIER_PASSWORD']);
} else {
	if (APPLICATION_ENV != 'development') {
		die('FATAL: No Memcachier Add-on found.');
	}
}
~~~