xref: /PHP-7.3/ext/filter/tests/014.phpt (revision 782352c5)
1--TEST--
2filter_var() and FILTER_VALIDATE_BOOLEAN
3--SKIPIF--
4<?php if (!extension_loaded("filter")) die("skip"); ?>
5--FILE--
6<?php
7
8class test {
9
10	function __toString() {
11		return "blah";
12	}
13}
14
15$t = new test;
16
17var_dump(filter_var("no", FILTER_VALIDATE_BOOLEAN));
18var_dump(filter_var(NULL, FILTER_VALIDATE_BOOLEAN));
19var_dump(filter_var($t, FILTER_VALIDATE_BOOLEAN));
20var_dump(filter_var(array(1,2,3,0,array("", "123")), FILTER_VALIDATE_BOOLEAN, FILTER_REQUIRE_ARRAY));
21var_dump(filter_var("yes", FILTER_VALIDATE_BOOLEAN));
22var_dump(filter_var("true", FILTER_VALIDATE_BOOLEAN));
23var_dump(filter_var("false", FILTER_VALIDATE_BOOLEAN));
24var_dump(filter_var("off", FILTER_VALIDATE_BOOLEAN));
25var_dump(filter_var("on", FILTER_VALIDATE_BOOLEAN));
26var_dump(filter_var("0", FILTER_VALIDATE_BOOLEAN));
27var_dump(filter_var("1", FILTER_VALIDATE_BOOLEAN));
28var_dump(filter_var("NONE", FILTER_VALIDATE_BOOLEAN));
29var_dump(filter_var("", FILTER_VALIDATE_BOOLEAN));
30var_dump(filter_var(-1, FILTER_VALIDATE_BOOLEAN));
31var_dump(filter_var("000000", FILTER_VALIDATE_BOOLEAN));
32var_dump(filter_var("111111", FILTER_VALIDATE_BOOLEAN));
33
34
35echo "Done\n";
36?>
37--EXPECT--
38bool(false)
39bool(false)
40bool(false)
41array(5) {
42  [0]=>
43  bool(true)
44  [1]=>
45  bool(false)
46  [2]=>
47  bool(false)
48  [3]=>
49  bool(false)
50  [4]=>
51  array(2) {
52    [0]=>
53    bool(false)
54    [1]=>
55    bool(false)
56  }
57}
58bool(true)
59bool(true)
60bool(false)
61bool(false)
62bool(true)
63bool(false)
64bool(true)
65bool(false)
66bool(false)
67bool(false)
68bool(false)
69bool(false)
70Done
71