Ini Set and Ini Restore Function in PHP

Introduction

I am describing the ini_set() and ini_restore() functions in PHP. First of all, I will discuss the ini_set() function.

The ini_set() function sets the value of the specified configuration option. The configuration option value will apply the new value of the script's execution time and the old value is resturned.

Syntax

ini_set ( "string $varname ", string $newvalue );

 

varname all the available option can be set using the ini_set() function.

 

newvalue new value for the option.

Example

<?php

    //undefined function calling

    error_reporting(E_ALL);

    ini_set("display_errors","on");

    echo "Line Before calling function ShowData()";

    Echo "<br>";

    //undefined function calling

    ShowDatad();

    echo "Line After calling function showData()";

 ?>

Output

ini function in php.jpg

And next, I will discuss the ini_restore() function in PHP. The PHP ini_restore() function restores the value of a configuration option to its original value.

Syntax

void ini_restore ( string $varname );

 

varname is the configuration option name.

 

Example

 

<?php

//y2k_compliance is using for parameter

$setting = 'y2k_compliance';

//PHP_EOL is a predefined constant in php

echo 'Current value \'' . $setting . '\': ' . ini_get($setting), PHP_EOL."<br>";

ini_set($setting, ini_get($setting) ? 0 : 1);

echo 'New value \'' . $setting . '\': ' . ini_get($setting), PHP_EOL."<br>";

//restore the configuration option value

ini_restore($setting);

echo 'Original value for \'' . $setting . '\': ' . ini_get($setting), PHP_EOL."<br>";

?>

Output

ini restore function in PHP.jpg

 

Up Next
    Ebook Download
    View all
    Learn
    View all