php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57014 Boolean return false on error
Submitted: 2006-05-15 04:14 UTC Modified: 2006-05-24 07:52 UTC
From: dev at pixandlog dot com Assigned: pajoye (profile)
Status: Closed Package: filter (PECL)
PHP Version: Irrelevant OS: Gentoo Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
30 - 25 = ?
Subscribe to this entry?

 
 [2006-05-15 04:14 UTC] dev at pixandlog dot com
Description:
------------
Hello.

I have found input_get with boolean weird. With a bad argument in form, i got a boolean false. Before i reciept value null.
It is not a good choice because we don't create a error message or exception without a differential value.
Please check revision R1.36 of logical_filters.c -> 
void php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL)
LINE=237
} else {
    zval_dtor(value);
    ZVAL_BOOL(value, 0);
}
------------------------
logical_filters.c - R1.21
void php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL)
LINE=218
} else {
    zval_dtor(value);
    Z_TYPE_P(value) = IS_NULL;
}
-------------------------
PHP5.1.4
Thanks you for your job.
Xavier.

Reproduce code:
---------------
<?php
//$_GET['test'] == 'foobar';
$source = INPUT_GET;
$name = 'test';
$ret = input_get($source, $name);
var_dump($ret);
if ($ret === null) {
    echo 'Error message.';
}
else {
    echo 'Good message.';
}
?>


Expected result:
----------------
NULL


Actual result:
--------------
false


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-15 04:16 UTC] dev at pixandlog dot com
Sorry i would wrote this :
<?php
//$_GET['test'] == 'foobar';
$source = INPUT_GET;
$name = 'test';
$filter = FILTER_VALIDATE_BOOLEAN;
$ret = input_get($source, $name, $filter);
var_dump($ret);
if ($ret === null) {
    echo 'Error message.';
}
else {
    echo 'Good message.';
}
?>
 [2006-05-15 07:02 UTC] pierre dot php at gmail dot com
It was changed with the latest addition to filter.

NULL is used is the value was not found. FALSE is the validation failed. In the case of a boolean value, it is not possible to differentiate them, but I think it is the correct behavior.

You should update your code, note that the filter API is not stable and may change, we cannot consider BC problems at this point.
 [2006-05-15 07:03 UTC] pierre dot php at gmail dot com
not bogus it yet, wrong select :)
 [2006-05-15 07:10 UTC] pierre dot php at gmail dot com
Another thought on this topic.

Where are used boolean values in forms? Mostly checkboxes, if a checkbox is not set, you do not see it in the posted data. From a filter point of view, it will end to NULL.

If it is returned but with an incorrect format (like someone is querying your script without using your form), filter will return false.

Is it not the safest way? or the more convenient?
 [2006-05-23 08:14 UTC] dev at pixandlog dot com
Hi.
Is it not the safest way? or the more convenient?
Why not !
I don't find an example with needed null value return.
Perhaps with more use of test and develop but now i don't 
see all case.
Thanks you for your job.
 [2006-05-23 10:23 UTC] dev at pixandlog dot com
Please update documentation.

- General Considerations
If the filter's expected input data mask does not match the provided data for logical filters the filter function returns "null".

Thank you.
 [2006-05-24 07:52 UTC] pierre dot php at gmail dot com
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 11:01:30 2024 UTC