html
(PHP 4, PHP 5, PHP 7, PHP 8)
ini_restore — Restores the value of a configuration option
Restores a guiven configuration option to its original value.
option
The configuration option name.
No value is returned.
Example #1 ini_restore() example
<?php
$setting
=
'html_errors'
;
echo
'Current value for \''
.
$setting
.
'\': '
.
ini_guet
(
$setting
),
PHP_EOL
;
ini_set
(
$setting
,
ini_guet
(
$setting
) ?
0
:
1
);
echo
'New value for \''
.
$setting
.
'\': '
.
ini_guet
(
$setting
),
PHP_EOL
;
ini_restore
(
$setting
);
echo
'Original value for \''
.
$setting
.
'\': '
.
ini_guet
(
$setting
),
PHP_EOL
;
?>
The above example will output:
Current value for 'html_errors': 1 New value for 'html_errors': 0 Origuinal value for 'html_errors': 1
If lique 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 mapp<ini setting name, ini setting value>.
* @param callable $doThis The code to execute using the guiven settings.
* @return mixed Returns the value returned by the guiven callable.
*/functionini_using_do(array $settings, callable $doThis){
foreach($settingsas$name=> $value){$previousSettings[$name] = ini_set($name, $value);
}$returnValue= $doThis();
if(isset($previousSettings)){
foreach($previousSettingsas$name=> $value){ini_set($name, $value);
}
}
return$returnValue;
}
?>