ini_restore

(PHP 4, PHP 5, PHP 7, PHP 8)

ini_restore設定オプションの値を元に戻す

説明

ini_restore(string $option): void

指定した設定オプションを元の値に戻します。

パラメータ

option

設定オプションの名前。

戻り値

値を返しません。

例1 ini_restore() の例

<?php
$setting
= 'html_errors';

echo
'Current value for \'' . $setting . '\': ' . ini_get($setting), PHP_EOL;

ini_set($setting, ini_get($setting) ? 0 : 1);
echo
'New value for \'' . $setting . '\': ' . ini_get($setting), PHP_EOL;

ini_restore($setting);
echo
'Original value for \'' . $setting . '\': ' . ini_get($setting), PHP_EOL;
?>

上の例の出力は以下となります。

Current value for 'html_errors': 1
New value for 'html_errors': 0
Original value for 'html_errors': 1

参考

  • ini_get() - 設定オプションの値を得る
  • ini_get_all() - すべての設定オプションを得る
  • ini_set() - 設定オプションの値を設定する

add a note

User Contributed Notes 1 note

up
4
Anonymous
9 years ago
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;}?>
To Top