|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 17:00:01 2025 UTC |
Description: ------------ The ini_get("boolean_setting") function may return several kind of value when dealing with boolean settings, as explained in the documentation : > Note: When querying boolean values > A boolean ini value of off will be returned as an empty string or "0" while a > boolean ini value of on will be returned as "1". The function can also return > the literal string of INI value. The last part is a really annoying behavior, as to get the boolean value of a boolean setting, the following must be done : $my_boolean = ini_get("boolean_setting"); if ($my_boolean === "0") { $my_boolean = false; } else { $my_lowered_boolean = strtolower($my_boolean); if ($my_lowered_boolean === "false" || $my_lowered_boolean === "off" || $my_lowered_boolean === "no") { $my_boolean = false; } else { $my_boolean = true; } } I've noticed that the behavior is different when the setting has been set in php.ini, or in apache's configuration. Settings from php.ini are always set to "" or "1", whereas apache's settings (via php_value) are set to their litteral value (ie: "FalsE", "oFF", "off", ...). Lot of chances that the devs miss it! When the setting doesn't exist, "" or null is returned. So that's quite a mess to deal with such values, and there is no way to test the existence of a setting. Test script: --------------- # Exemple 1 # httpd.conf php_admin_value safe_mode FaLsE # php script ini_get("safe_mode") === "FaLsE" --- # Exemple 2 # php.ini safe_mode = FaLsE # php script ini_get("safe_mode") === "" Expected result: ---------------- It would be a great enhancement no to depend on what is written in configuration files, but to depend on the way it's being interpreted by the engine. # Example 1 # httpd.conf php_admin_value safe_mode FaLsE # php script ini_get("safe_mode") === false --- # Example 2 # php.ini safe_mode = FaLsE # php script ini_get("safe_mode") === false --- # Example 3 # Non existing setting ini_get("unset_setting") === null Actual result: -------------- A disabled boolean setting may return one of the following: ini_get("safe_mode") === "FaLsE" ini_get("safe_mode") === "Off" ini_get("safe_mode") === "oFF" ini_get("safe_mode") === "0" ... An enabled boolean setting may return one of the following: ini_get("safe_mode") === "truE" ini_get("safe_mode") === "On" ini_get("safe_mode") === "oN" ini_get("safe_mode") === "1" ... An unset setting may return one of the following: ini_get("safe_mode") === "" ini_get("safe_mode") === null