ID:               33443
 User updated by:  nickj-phpbugs at nickj dot org
-Summary:          ini_get("allow_url_fopen") should return boolean
                   string, not the literal string
 Reported By:      nickj-phpbugs at nickj dot org
 Status:           Assigned
 Bug Type:         Documentation problem
 Operating System: Debian Woody GNU/Linux 3.0r6
 PHP Version:      5CVS-2005-06-23 (dev)
 Assigned To:      tony2001
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2005-06-23 13:13:13] [EMAIL PROTECTED]

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-23 06:41:57] 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 06:28:12] 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.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33443&edit=1

Reply via email to