Req #52168 [NEW]: ini_get() better consistent behavior with booleans

From: Date: Thu, 24 Jun 2010 09:21:31 +0000
Subject: Req #52168 [NEW]: ini_get() better consistent behavior with booleans
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-151830@lists.php.net to get a copy of this message
From: Operating system: GNU/Linux PHP version: Irrelevant Package: PHP options/info functions Bug Type: Feature/Change Request Bug description:ini_get() better consistent behavior with booleans 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 -- Edit bug report at http://bugs.php.net/bug.php?id=52168&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52168&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52168&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52168&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52168&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52168&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52168&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52168&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52168&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52168&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52168&r=support Expected behavior: http://bugs.php.net/fix.php?id=52168&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52168&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52168&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52168&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52168&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52168&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52168&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52168&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52168&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52168&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52168&r=mysqlcfg

« previous php.bugs (#151830) next »