...from FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE
The remainer of the fix would require the filter functions to only
convert to string when it makes sense for that particular filter.
ce = Z_OBJCE_P(value);
if (!ce->__tostring) {
zval_ptr_dtor(value);
- ZVAL_FALSE(value);
+ /* #67167: doesn't return null on failure for objects */
+ if (flags & FILTER_NULL_ON_FAILURE) {
+ ZVAL_NULL(value);
+ } else {
+ ZVAL_FALSE(value);
+ }
return;
}
}
--- /dev/null
+--TEST--
+Bug #67167: object with VALIDATE_BOOLEAN and NULL_ON_FAILURE
+
+--SKIPIF--
+<?php if (!extension_loaded("filter")) die("skip"); ?>
+
+--FILE--
+<?php
+var_dump(filter_var(
+ new \StdClass(),
+ FILTER_VALIDATE_BOOLEAN,
+ FILTER_NULL_ON_FAILURE
+));
+
+--EXPECTF--
+NULL
--- /dev/null
+--TEST--
+Bug #67167: filter_var(null,FILTER_VALIDATE_BOOLEAN,FILTER_NULL_ON_FAILURE) returns null
+
+--SKIPIF--
+<?php if (!extension_loaded("filter")) die("skip"); ?>
+
+--FILE--
+<?php
+var_dump(filter_var(
+ null,
+ FILTER_VALIDATE_BOOLEAN,
+ FILTER_NULL_ON_FAILURE
+));
+
+--XFAIL--
+Requires php_zval_filter to not use convert_to_string for all filters.
+
+--EXPECTF--
+NULL
+