Function ini_get_all Now Includes Built-in Default Value in PHP 8.6

Function ini_get_all Now Includes Built-in Default Value in PHP 8.6

The ini_get_all function returns an array of all INI directives together with details about each one. Since PHP 8.6, this array contains a new builtin_default_value key, which holds the value compiled into PHP. Before PHP 8.6, there was no way to read this value at runtime.

The following code changes the memory_limit directive at runtime and prints its details:

<?php

ini_set('memory_limit', '512M');

print_r(ini_get_all()['memory_limit']);

Before PHP 8.6:

Array
(
    [global_value] => -1
    [local_value] => 512M
    [access] => 7
)

Since PHP 8.6:

Array
(
    [global_value] => -1
    [local_value] => 512M
    [builtin_default_value] => 128M
    [access] => 7
)

The global_value key shows -1, because php.ini contains memory_limit = -1. The local_value key shows 512M, because ini_set changed the value at runtime. The builtin_default_value key shows 128M, which is the default value of memory_limit in PHP.

The builtin_default_value key is never affected by php.ini, the -d command line option or ini_set. It changes only if PHP itself is built with a different default.

Some directives have no built-in default value, such as error_log and auto_prepend_file. For these directives, the builtin_default_value key is null.

The second argument of ini_get_all must be true to get the details, which is the default. With false, the function returns only the current value of each directive, such as 512M for memory_limit.

Leave a Comment

Cancel reply

Your email address will not be published.