(PHP 4, PHP 5, PHP 7, PHP 8)
ini_restore — Restaura el valor de la opción de configuración
Restaura el valor original de la opción de configuración
varname.
optionEl nombre de la opción de configuración.
No se retorna ningún valor.
Ejemplo #1 Ejemplo con ini_restore()
<?php
$setting = 'html_errors';
echo 'Valor actual de \'' . $setting . '\': ' . ini_get($setting), PHP_EOL;
ini_set($setting, ini_get($setting) ? 0 : 1);
echo 'Nuevo valor de \'' . $setting . '\': ' . ini_get($setting), PHP_EOL;
ini_restore($setting);
echo 'Valor original de \'' . $setting . '\': ' . ini_get($setting), PHP_EOL;
?>El ejemplo anterior mostrará:
Valor actual de 'html_errors': 1 Nuevo valor de 'html_errors': 0 Valor original de 'html_errors': 1
If like me you thought ini_restore() would restore to the most recent setting rather than the startup value, you could use this.
<?php
/**
* Executes a function using a custom PHP configuration.
*
* @param array $settings A map<ini setting name, ini setting value>.
* @param callable $doThis The code to execute using the given settings.
* @return mixed Returns the value returned by the given callable.
*/
function ini_using_do(array $settings, callable $doThis){
foreach($settings as $name => $value){
$previousSettings[$name] = ini_set($name, $value);
}
$returnValue = $doThis();
if(isset($previousSettings)){
foreach($previousSettings as $name => $value){
ini_set($name, $value);
}
}
return $returnValue;
}
?>