php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70409 FILTER_NULL_ON_FAILURE returns false for null input for FILTER_VALIDATE_BOOLEAN
Submitted: 2015-09-02 12:11 UTC Modified: 2019-01-02 00:58 UTC
Votes:6
Avg. Score:3.7 ± 0.7
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: thedavidmeister at gmail dot com Assigned:
Status: Verified Package: Filter related
PHP Version: 5.6.13RC1 OS: Mac OS X
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-09-02 12:11 UTC] thedavidmeister at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/filter.filters.validate
---

Docs say:

Returns TRUE for "1", "true", "on" and "yes". Returns FALSE otherwise.

If FILTER_NULL_ON_FAILURE is set, FALSE is returned only for "0", "false", "off", "no", and "", and NULL is returned for all non-boolean values.

Actual, unexpected behaviour:

null will return false when FILTER_NULL_ON_FAILURE is set because everything is cast to a string before the filter_var() checks are applied - https://bugs.php.net/bug.php?id=67167&edit=2

Expected behaviour:

Update the documentation to explain that null will return false.

Test script:
---------------
// null is treated as boolean false by filter_var().
filter_var(null, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)

=> false

// null is not actually a boolean.
is_bool(null)

=> false


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-02 13:43 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2015-09-02 13:43 UTC] cmb@php.net
Actually, FALSE is returned for all values that yield one of the
listed values when being converted to string, e.g. the following
yield FALSE:

  filter_var(false, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)
  filter_var(0, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)
  
Furthermore (all?) objects yield FALSE, e.g.

  filter_var((object) [1], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)
 [2015-11-09 14:02 UTC] bugs dot php dot net_nospam at adviesenzo dot nl
Duplicate of https://bugs.php.net/bug.php?id=68761 ?
 [2019-01-02 00:58 UTC] girgias@php.net
-Package: Documentation problem +Package: Filter related
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 22:01:28 2019 UTC