PHP: ini_restore - Manual (original) (raw)
(PHP 4, PHP 5, PHP 7, PHP 8)
ini_restore — Restores the value of a configuration option
Description
Parameters
option
The configuration option name.
Return Values
No value is returned.
Examples
Example #1 ini_restore() example
`<?php
$setting = 'html_errors';
echo
'Current value for '' . setting.′:ˊ′.iniget(setting . '': ' . ini_get(setting.′:ˊ′.iniget(setting), PHP_EOL;ini_set($setting, ini_get($setting) ? 0 : 1);
echo 'New value for '' . setting.′:ˊ′.iniget(setting . '': ' . ini_get(setting.′:ˊ′.iniget(setting), PHP_EOL;ini_restore($setting);
echo 'Original value for '' . setting.′:ˊ′.iniget(setting . '': ' . ini_get(setting.′:ˊ′.iniget(setting), PHP_EOL;
?>`
The above example will output:
Current value for 'html_errors': 1 New value for 'html_errors': 0 Original value for 'html_errors': 1
See Also
- ini_get() - Gets the value of a configuration option
- ini_get_all() - Gets all configuration options
- ini_set() - Sets the value of a configuration option
Found A Problem?
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 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>e</mi><mi>t</mi><mi>t</mi><mi>i</mi><mi>n</mi><mi>g</mi><mi>s</mi><mo separator="true">,</mo><mi>c</mi><mi>a</mi><mi>l</mi><mi>l</mi><mi>a</mi><mi>b</mi><mi>l</mi><mi>e</mi></mrow><annotation encoding="application/x-tex">settings, callable </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">se</span><span class="mord mathnormal">tt</span><span class="mord mathnormal">in</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal">s</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.01968em;">ll</span><span class="mord mathnormal">ab</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span></span></span></span>doThis){
foreach($settings as <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><mo>></mo></mrow><annotation encoding="application/x-tex">name => </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mord mathnormal">nam</span><span class="mord mathnormal">e</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=></span></span></span></span>value){
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mi>r</mi><mi>e</mi><mi>v</mi><mi>i</mi><mi>o</mi><mi>u</mi><mi>s</mi><mi>S</mi><mi>e</mi><mi>t</mi><mi>t</mi><mi>i</mi><mi>n</mi><mi>g</mi><mi>s</mi><mo stretchy="false">[</mo></mrow><annotation encoding="application/x-tex">previousSettings[</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">p</span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">i</span><span class="mord mathnormal">o</span><span class="mord mathnormal">u</span><span class="mord mathnormal">s</span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mord mathnormal">e</span><span class="mord mathnormal">tt</span><span class="mord mathnormal">in</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal">s</span><span class="mopen">[</span></span></span></span>name] = ini_set($name, $value);
}
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mi>e</mi><mi>t</mi><mi>u</mi><mi>r</mi><mi>n</mi><mi>V</mi><mi>a</mi><mi>l</mi><mi>u</mi><mi>e</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">returnValue = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">re</span><span class="mord mathnormal">t</span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">nVa</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">u</span><span class="mord mathnormal">e</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>doThis();
if(isset($previousSettings)){
foreach($previousSettings as <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><mo>></mo></mrow><annotation encoding="application/x-tex">name => </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mord mathnormal">nam</span><span class="mord mathnormal">e</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=></span></span></span></span>value){
ini_set($name, $value);
}
}
return $returnValue;
}
?>