PHP 8.2: INI Parsing warnings

Version8.2
TypeChange

In PHP 8.2, PHP adds a new function named ini_parse_quantity() that parses a string value containing a data size such as 2M, 5G, 1G into an integer containing the size, with M, G, and K multipliers resolved.

As part of this change, PHP 8.2 also emits warnings when it encounters ill-formatted INI values on INI settings that expect an integer value. This behavior is now consistent and identical to setting INI values in .ini files, passing INI values to PHP's CLI (php -d setting=value), ini_set function, and other means of configuration provided server APIs.

See the ini_parse_quantity: Warnings section for a detailed list of error conditions. Most notably, PHP does not support common data size suffixes such as MB, and only supports (case independent) K, M, and G suffixes.

Note that the parsed integers value for all of the INI settings remain the same; the difference is that since PHP 8.2, PHP emits a warning that was previously silently ignored.

Examples of INI values that trigger the warnings

The following are some of the examples that might trigger a warning in PHP 8.2. The interpreted value remains unchanged in PHP 8.2, and should not cause any other functional changes other than the additional warning.


# custom php.ini file
upload_max_filesize = 2GB
Warning: Invalid "upload_max_filesize" setting. Invalid quantity "2GB": unknown multiplier "B", interpreting as "2" for backwards compatibility

# Running PHP script
php -d post_max_size=999999999999G
Warning: Invalid "post_max_size" setting. Invalid quantity "999999999999G": value is out of range, using overflow result for backwards compatibility

ini_set('session.gc_maxlifetime', 'MB50');
Warning:  Invalid "session.gc_maxlifetime" setting. Invalid quantity "MB50": no valid leading digits, interpreting as "0" for backwards compatibility

Correcting the INI values

An INI value correctly parsed in PHP 8.2 without warnings should yield identical values in all PHP versions including older PHP versions. ini_parse_quantity: Warnings section lists all possible warning patterns, but the following is a list of examples that show examples of fixes.

# custom php.ini file
- upload_max_filesize = 2GB
+ upload_max_filesize = 2G
# Running PHP script
- php -d post_max_size=999999999999G
+ php -d post_max_size=9G # Change value to a value that does not overflow
- ini_set('session.gc_maxlifetime', 'MB50');
+ ini_set('session.gc_maxlifetime', '50M');

Affected PHP INI Directives

The following is a list of INI directives affected within PHP core and extensions. Third party extensions, such as Xdebug also declare INI settings, and they are affected by this change as well.

  • bcmath.scale
  • com.code_page
  • default_socket_timeout
  • fiber.stack_size
  • hard_timeout
  • intl.error_level
  • ldap.max_links
  • max_input_nesting_level
  • max_input_vars
  • mbstring.regex_retry_limit
  • mbstring.regex_stack_limit
  • mysqli.allow_local_infile
  • mysqli.allow_persistent
  • mysqli.default_port
  • mysqli.max_links
  • mysqli.max_persistent
  • mysqli.reconnect
  • mysqli.rollback_on_cached_plink
  • mysqlnd.log_mask
  • mysqlnd.mempool_default_size
  • mysqlnd.net_read_buffer_size
  • mysqlnd.net_read_timeout
  • oci8.default_prefetch
  • oci8.max_persistent
  • oci8.persistent_timeout
  • oci8.ping_interval
  • oci8.prefetch_lob_size
  • oci8.privileged_connect
  • oci8.statement_cache_size
  • odbc.allow_persistent
  • odbc.check_persistent
  • odbc.defaultbinmode
  • odbc.default_cursortype
  • odbc.defaultlrl
  • odbc.max_links
  • odbc.max_persistent
  • opcache.consistency_checks
  • opcache.file_update_protection
  • opcache.force_restart_timeout
  • opcache.interned_strings_buffer
  • opcache.jit_bisect_limit
  • opcache.jit_blacklist_root_trace
  • opcache.jit_blacklist_side_trace
  • opcache.jit_debug
  • opcache.jit_hot_func
  • opcache.jit_hot_loop
  • opcache.jit_hot_return
  • opcache.jit_hot_side_exit
  • opcache.jit_max_exit_counters
  • opcache.jit_max_loop_unrolls
  • opcache.jit_max_polymorphic_calls
  • opcache.jit_max_recursive_calls
  • opcache.jit_max_recursive_returns
  • opcache.jit_max_root_traces
  • opcache.jit_max_side_traces
  • opcache.log_verbosity_level
  • opcache.max_file_size
  • opcache.opt_debug_level
  • opcache.optimization_level
  • opcache.revalidate_freq
  • output_buffering
  • pcre.backtrack_limit
  • pcre.recursion_limit
  • pgsql.max_links
  • pgsql.max_persistent
  • post_max_size
  • realpath_cache_size
  • realpath_cache_ttl
  • session.cache_expire
  • session.cookie_lifetime
  • session.gc_divisor
  • session.gc_maxlifetime
  • session.gc_probability
  • soap.wsdl_cache_limit
  • soap.wsdl_cache_ttl
  • unserialize_max_depth
  • upload_max_filesize
  • user_ini.cache_ttl
  • xmlrpc_error_number
  • zend.assertions
  • zlib.output_compression_level

INI settings declared by most common third-party extensions:

Xdebug

  • xdebug.connect_timeout_ms
  • xdebug.force_display_errors
  • xdebug.force_error_reporting
  • xdebug.halt_level
  • xdebug.log_level
  • xdebug.max_nesting_level
  • xdebug.max_stack_frames
  • xdebug.profiler_append
  • xdebug.show_error_trace
  • xdebug.show_exception_trace
  • xdebug.show_local_vars
  • xdebug.trace_format
  • xdebug.trace_options
  • xdebug.var_display_max_children
  • xdebug.var_display_max_data
  • xdebug.var_display_max_depth

Pcov

  • pcov.initial.memory
  • pcov.initial.files

APCu

  • apc.shm_segments
  • apc.shm_size
  • apc.entries_hint
  • apc.ttl
  • apc.gc_ttl
  • apc.slam_defense
  • apc.use_request_time
  • apc.coredump_unmap

Backwards Compatibility Impact

This change does not alter the final values PHP parses, so this change should not introduce any difference in the functionality. The additional warnings are helpful, as they try to warn about some of the most common patterns that PHP did not parse as commonly expected, but did so silently.

It is straight-forward to fix the INI values in a cross-version compatible way, as shown in the examples.

The list of affected INI directives is non-exhaustive; there can be other INI directives added by third party PHP extensions that trigger the same warning.

Related Changes


Implementation