xref: /PHP-8.3/ext/filter/tests/039.phpt (revision 74859783)
1--TEST--
2filter_var_array() and different arguments
3--EXTENSIONS--
4filter
5--FILE--
6<?php
7
8echo "-- (1)\n";
9var_dump(filter_var_array(array()));
10var_dump(filter_var_array(array(1,"blah"=>"hoho")));
11var_dump(filter_var_array(array(), -1));
12var_dump(filter_var_array(array(), 1000000));
13
14try {
15    filter_var_array(array(), "");
16} catch (TypeError $exception) {
17    echo $exception->getMessage() . "\n";
18}
19
20echo "-- (2)\n";
21var_dump(filter_var_array(array(""=>""), -1));
22var_dump(filter_var_array(array(""=>""), 1000000));
23
24try {
25    filter_var_array(array(""=>""), "");
26} catch (TypeError $exception) {
27    echo $exception->getMessage() . "\n";
28}
29
30echo "-- (3)\n";
31var_dump(filter_var_array(array("aaa"=>"bbb"), -1));
32var_dump(filter_var_array(array("aaa"=>"bbb"), 1000000));
33
34try {
35    filter_var_array(array("aaa"=>"bbb"), "");
36} catch (TypeError $exception) {
37    echo $exception->getMessage() . "\n";
38}
39
40echo "-- (4)\n";
41
42try {
43    filter_var_array(array(), new stdclass);
44} catch (TypeError $exception) {
45    echo $exception->getMessage() . "\n";
46}
47
48var_dump(filter_var_array(array(), array()));
49var_dump(filter_var_array(array(), array("var_name"=>1)));
50var_dump(filter_var_array(array(), array("var_name"=>-1)));
51var_dump(filter_var_array(array("var_name"=>""), array("var_name"=>-1)));
52
53echo "-- (5)\n";
54try {
55    filter_var_array(array("var_name"=>""), array("var_name"=>-1, "asdas"=>"asdasd", "qwe"=>"rty", ""=>""));
56} catch (ValueError $exception) {
57    echo $exception->getMessage() . "\n";
58}
59try {
60    filter_var_array(array("asdas"=>"text"), array("var_name"=>-1, "asdas"=>"asdasd", "qwe"=>"rty", ""=>""));
61} catch (ValueError $exception) {
62    echo $exception->getMessage() . "\n";
63}
64
65$a = array(""=>""); $b = -1;
66var_dump(filter_var_array($a, $b));
67var_dump($a, $b);
68
69$a = array(""=>""); $b = 100000;
70var_dump(filter_var_array($a, $b));
71var_dump($a, $b);
72
73$a = array(""=>""); $b = "";
74try {
75    filter_var_array($a, $b);
76} catch (TypeError $exception) {
77    echo $exception->getMessage() . "\n";
78}
79var_dump($a, $b);
80
81echo "Done\n";
82?>
83--EXPECTF--
84-- (1)
85array(0) {
86}
87array(2) {
88  [0]=>
89  string(1) "1"
90  ["blah"]=>
91  string(4) "hoho"
92}
93
94Warning: filter_var_array(): Unknown filter with ID -1 in %s on line %d
95bool(false)
96
97Warning: filter_var_array(): Unknown filter with ID 1000000 in %s on line %d
98bool(false)
99filter_var_array(): Argument #2 ($options) must be of type array|int, string given
100-- (2)
101
102Warning: filter_var_array(): Unknown filter with ID -1 in %s on line %d
103bool(false)
104
105Warning: filter_var_array(): Unknown filter with ID 1000000 in %s on line %d
106bool(false)
107filter_var_array(): Argument #2 ($options) must be of type array|int, string given
108-- (3)
109
110Warning: filter_var_array(): Unknown filter with ID -1 in %s on line %d
111bool(false)
112
113Warning: filter_var_array(): Unknown filter with ID 1000000 in %s on line %d
114bool(false)
115filter_var_array(): Argument #2 ($options) must be of type array|int, string given
116-- (4)
117filter_var_array(): Argument #2 ($options) must be of type array|int, stdClass given
118array(0) {
119}
120array(1) {
121  ["var_name"]=>
122  NULL
123}
124array(1) {
125  ["var_name"]=>
126  NULL
127}
128array(1) {
129  ["var_name"]=>
130  string(0) ""
131}
132-- (5)
133filter_var_array(): Argument #2 ($options) cannot contain empty keys
134filter_var_array(): Argument #2 ($options) cannot contain empty keys
135
136Warning: filter_var_array(): Unknown filter with ID -1 in %s on line %d
137bool(false)
138array(1) {
139  [""]=>
140  string(0) ""
141}
142int(-1)
143
144Warning: filter_var_array(): Unknown filter with ID 100000 in %s on line %d
145bool(false)
146array(1) {
147  [""]=>
148  string(0) ""
149}
150int(100000)
151filter_var_array(): Argument #2 ($options) must be of type array|int, string given
152array(1) {
153  [""]=>
154  string(0) ""
155}
156string(0) ""
157Done
158