总有人间一两风,填我十万八千梦

PHP ini_restore 用法 手册 | 示例代码

PHP开发手册 归档 265℃ 0评论

ini_restore

(PHP 4, PHP 5, PHP 7)

ini_restore恢复配置选项的值

说明

ini_restore ( string $varname ) : void

恢复指定的配置选项到它的原始值。

参数

varname

配置选项名称。

返回值

没有返回值。

范例

Example #1 ini_restore() 例子

<?php
$setting 
'y2k_compliance';

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

ini_set($settingini_get($setting) ? 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 'y2k_compliance': 1
New value for 'y2k_compliance': 0
Original value for 'y2k_compliance': 1

参见

用户贡献的笔记

Anonymous

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;
}

?>

转载请注明:悠然品鉴 » PHP ini_restore 用法 手册 | 示例代码

喜欢 (0)or分享 (0)
发表我的评论
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址