Doc #70409 [Opn->Ver]: FILTER_NULL_ON_FAILURE returns false for null input for FILTER_VALIDATE_BOOLEAN

From: Date: Wed, 02 Sep 2015 13:43:56 +0000
Subject: Doc #70409 [Opn->Ver]: FILTER_NULL_ON_FAILURE returns false for null input for FILTER_VALIDATE_BOOLEAN
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-12700@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70409&edit=1 ID: 70409 Updated by: cmb@php.net Reported by: thedavidmeister at gmail dot com Summary: FILTER_NULL_ON_FAILURE returns false for null input for FILTER_VALIDATE_BOOLEAN -Status: Open +Status: Verified Type: Documentation Problem Package: Documentation problem Operating System: Mac OS X PHP Version: 5.6.13RC1 Block user comment: N Private report: N New Comment: 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) Previous Comments: ------------------------------------------------------------------------ [2015-09-02 12:11:57] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70409&edit=1

« previous php.doc.bugs (#12700) next »