php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #33443 ini_get(any boolean directive) returns literal INI string, not a boolean string.
Submitted: 2005-06-23 06:28 UTC Modified: 2007-08-20 14:02 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: nickj-phpbugs at nickj dot org Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
 [2005-06-23 06:28 UTC] nickj-phpbugs at nickj dot org
Description:
------------
Currently ini_get("allow_url_fopen") appears to return a literal string, not a boolean value/string. For example, if the php.ini contains "allow_url_fopen = on", then ini_get("allow_url_fopen") will return "on", not "1". This is inconsistent with the documentation.

The php.ini documentation at http://au3.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen says 'allow_url_fopen' is a "boolean" configuration directive.

The ini_get() documentation at http://php.net/ini-get says:
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".

Therefore, if the php.ini contains "allow_url_fopen = on", then ini_get("allow_url_fopen") should return "1"; but it does not.

Additionally, in the php.ini itself, it lists the supported INI boolean constants as being "On, Off, True, False, Yes, No and None". It would therefore probably be good if (in addition to the 'on' and 'off' constants) the 'true', 'false', 'yes', 'no' and 'none' constants worked in the same way as well.

I have written a series of small .phpt PHP unit-tests that demonstrate the above, and I will add a URL for these in the next few minutes.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-23 06:41 UTC] nickj-phpbugs at nickj dot org
The .phpt unit-tests are now available for download at: http://home.swiftdsl.com.au/~npj/php-bugs/bug33443.zip (3KB file)

The results of running them on a PHP-5.1-dev build a few hours old was as follows:
-----------------------------------------------------------------------
ludo:~/tmp/php-5.1-dev/php5-200506222230# TEST_PHP_EXECUTABLE=sapi/cli/php sapi/cli/php run-tests.php ../bug33443/*.phpt

=====================================================================
CWD         : /root/tmp/php-5.1-dev/php5-200506222230
PHP         : sapi/cli/php 
PHP_SAPI    : cli
PHP_VERSION : 5.1.0-dev
ZEND_VERSION: 2.1.0-dev
PHP_OS      : Linux - Linux ludo 2.6.7-1-686 #1 Wed Jul 28 12:29:51 CEST 2004 i686
INI actual  : /root/tmp/php-5.1-dev/php5-200506222230/sapi/cli/php.ini
More .INIs  : 
Extra dirs  : 
=====================================================================
Running selected tests.
PASS Bug #33443 [0] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-0.phpt]
PASS Bug #33443 [1] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-1.phpt]
FAIL Bug #33443 [false] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-false.phpt]
FAIL Bug #33443 [no] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-no.phpt]
FAIL Bug #33443 [none] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-none.phpt]
FAIL Bug #33443 [off] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-off.phpt]
FAIL Bug #33443 [on-literal] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-on-literal.phpt]
PASS Bug #33443 [on] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-on.phpt]
PASS Bug #33443 [true] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-true.phpt]
PASS Bug #33443 [yes] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-yes.phpt]

=====================================================================
Number of tests :   10                10
Tests skipped   :    0 (  0.0%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :    5 ( 50.0%) ( 50.0%)
Tests passed    :    5 ( 50.0%) ( 50.0%)
---------------------------------------------------------------------
Time taken      :    0 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Bug #33443 [false] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-false.phpt]
Bug #33443 [no] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-no.phpt]
Bug #33443 [none] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-none.phpt]
Bug #33443 [off] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-off.phpt]
Bug #33443 [on-literal] (ini_get("allow_url_fopen") should return boolean string, not the literal string) [/root/tmp/php-5.1-dev/bug33443/bug33443-on-literal.phpt]
=====================================================================
ludo:~/tmp/php-5.1-dev/php5-200506222230# 
-----------------------------------------------------------------------
 [2005-06-23 13:13 UTC] tony2001@php.net
There no way to change it right now, as it will require a lot of changes in the engine and extensions.
I'll change the docs to mention it.
 [2005-06-24 08:30 UTC] nickj-phpbugs at nickj dot org
I've just written a test-generator that creates .phpt tests for the php.ini boolean directives, and I can safely say that the functioning of ini_get() with most boolean values is really not good. 

So it's not just 'allow_fopen_url' that does not work as documented with values like 'on', 'off', 'true', 'false', 'yes', and 'no'.

I made a test of roughly 67 boolean php.ini directives. It seems that 28 of these directives are hard-coded to be off (i.e. they ignore the configuration directives), so they're impossible to test.

Of the remaining 39 boolean php.ini directives, I could not find a single php.ini directive that passed every boolean test (0, 1, 'on', 'off', 'true', 'false', 'yes', 'no', 'none'). In fact, I could not even find a boolean php.ini directive that passed the 'on' test, which is the specific example used in the documentation. So there is not a single one that works as documented.

The only thing which does seem to work is to use '0' and '1' for the non-hard-coded boolean directives. For everything else, including 'on' and 'off', ini_get() is simply not going to work as expected.

The test generator script is available for download at http://home.swiftdsl.com.au/~npj/php-bugs/generate-ini-get-tests.phps
(Simply put it in an empty directory and run it, and it will generate 612 .phpt tests, which can then be run as normal for .phpt tests)

Based on the above, can I please make a suggestion? How about two functions:
* ini_get() - retain the current function (which returns the literal string), thus retaining backwards compatibility.
* ini_get_boolean() - returns a true boolean for boolean php.ini directives. Should return either 'true' or 'false' (as distinct from "0", "1" or ""), as then it never needs the (boolean) cast. Internally, it could call ini_get(), and compare it to 0, 1, 'on', 'off', 'true', 'false', 'yes', 'no', 'none', and return the appropriate result.
 [2005-07-08 12:02 UTC] vrana@php.net
Tony, what do you mean by "lot of changes in the engine and extensions"? Since allow_url_fopen and others have on_modify handler set to OnUpdateBool, everything should work, shouldn't it? It seems to me that there is simply some bug causing that boolean value isn't converted under some circumstances.

BTW ini_get("allow_url_fopen") returns "1" for me (Win XP, PHP 5.0.4), but ini_set("display_errors", "On"); echo ini_get("display_errors"); displays "On".
 [2007-06-17 23:23 UTC] phpbugs at thequod dot de
After 2 years the documentation has still not been fixed.
See http://php.net/ini_get
 [2007-08-20 14:02 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"The function can also return the literal string of INI value."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 15 18:01:34 2024 UTC