Doc #70409 [Com]: FILTER_NULL_ON_FAILURE returns false for null input for FILTER_VALIDATE_BOOLEAN

From: Date: Mon, 09 Nov 2015 14:02:01 +0000
Subject: Doc #70409 [Com]: 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-12860@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 Comment by: bugs dot php dot net_nospam at adviesenzo dot nl Reported by: thedavidmeister at gmail dot com Summary: FILTER_NULL_ON_FAILURE returns false for null input for FILTER_VALIDATE_BOOLEAN 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: Duplicate of https://bugs.php.net/bug.php?id=68761 ? Previous Comments: ------------------------------------------------------------------------ [2015-09-02 13:43:55] 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-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 (#12860) next »