1--TEST--
2Test iconv_strpos() function : usage variations - pass different data types as $charset arg
3--SKIPIF--
4<?php
5extension_loaded('iconv') or die('skip');
6function_exists('iconv_strpos') or die("skip iconv_strpos() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : int iconv_strpos(string haystack, string needle [, int offset [, string charset]])
11 * Description: Find position of first occurrence of a string within another
12 * Source code: ext/iconv/iconv.c
13 */
14
15
16/*
17 * Pass iconv_strpos different data types as $encoding arg to test behaviour
18 * Where possible 'UTF-8' has been entered as a string value
19 */
20
21echo "*** Testing iconv_strpos() : usage variations ***\n";
22
23// Initialise function arguments not being substituted
24$haystack = b'string_val';
25$needle = b'val';
26$offset = 0;
27
28//get an unset variable
29$unset_var = 10;
30unset ($unset_var);
31
32// get a class
33class classA
34{
35  public function __toString() {
36    return "UTF-8";
37  }
38}
39
40// heredoc string
41$heredoc = <<<EOT
42UTF-8
43EOT;
44
45// get a resource variable
46$fp = fopen(__FILE__, "r");
47
48// unexpected values to be passed to $input argument
49$inputs = array(
50
51       // int data
52/*1*/  0,
53       1,
54       12345,
55       -2345,
56
57       // float data
58/*5*/  10.5,
59       -10.5,
60       12.3456789000e10,
61       12.3456789000E-10,
62       .5,
63
64       // null data
65/*10*/ NULL,
66       null,
67
68       // boolean data
69/*12*/ true,
70       false,
71       TRUE,
72       FALSE,
73
74       // empty data
75/*16*/ "",
76       '',
77
78       // string data
79/*18*/ "UTF-8",
80       'UTF-8',
81       $heredoc,
82
83       // object data
84/*21*/ new classA(),
85
86       // undefined data
87/*22*/ @$undefined_var,
88
89       // unset data
90/*23*/ @$unset_var,
91
92       // resource variable
93/*24*/ $fp
94);
95
96// loop through each element of $inputs to check the behavior of iconv_strpos()
97$iterator = 1;
98foreach($inputs as $input) {
99  echo "\n-- Iteration $iterator --\n";
100  var_dump( iconv_strpos($haystack, $needle, $offset, $input));
101  $iterator++;
102};
103
104fclose($fp);
105
106echo "Done";
107?>
108
109--EXPECTF--
110*** Testing iconv_strpos() : usage variations ***
111
112-- Iteration 1 --
113
114Notice: iconv_strpos(): Wrong charset, conversion from `0' to `UCS-4LE' is not allowed in %s on line %d
115bool(false)
116
117-- Iteration 2 --
118
119Notice: iconv_strpos(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d
120bool(false)
121
122-- Iteration 3 --
123
124Notice: iconv_strpos(): Wrong charset, conversion from `12345' to `UCS-4LE' is not allowed in %s on line %d
125bool(false)
126
127-- Iteration 4 --
128
129Notice: iconv_strpos(): Wrong charset, conversion from `-2345' to `UCS-4LE' is not allowed in %s on line %d
130bool(false)
131
132-- Iteration 5 --
133
134Notice: iconv_strpos(): Wrong charset, conversion from `10.5' to `UCS-4LE' is not allowed in %s on line %d
135bool(false)
136
137-- Iteration 6 --
138
139Notice: iconv_strpos(): Wrong charset, conversion from `-10.5' to `UCS-4LE' is not allowed in %s on line %d
140bool(false)
141
142-- Iteration 7 --
143
144Notice: iconv_strpos(): Wrong charset, conversion from `123456789000' to `UCS-4LE' is not allowed in %s on line %d
145bool(false)
146
147-- Iteration 8 --
148
149Notice: iconv_strpos(): Wrong charset, conversion from `1.23456789E-9' to `UCS-4LE' is not allowed in %s on line %d
150bool(false)
151
152-- Iteration 9 --
153
154Notice: iconv_strpos(): Wrong charset, conversion from `0.5' to `UCS-4LE' is not allowed in %s on line %d
155bool(false)
156
157-- Iteration 10 --
158int(7)
159
160-- Iteration 11 --
161int(7)
162
163-- Iteration 12 --
164
165Notice: iconv_strpos(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d
166bool(false)
167
168-- Iteration 13 --
169int(7)
170
171-- Iteration 14 --
172
173Notice: iconv_strpos(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d
174bool(false)
175
176-- Iteration 15 --
177int(7)
178
179-- Iteration 16 --
180int(7)
181
182-- Iteration 17 --
183int(7)
184
185-- Iteration 18 --
186int(7)
187
188-- Iteration 19 --
189int(7)
190
191-- Iteration 20 --
192int(7)
193
194-- Iteration 21 --
195int(7)
196
197-- Iteration 22 --
198int(7)
199
200-- Iteration 23 --
201int(7)
202
203-- Iteration 24 --
204
205Warning: iconv_strpos() expects parameter 4 to be string, resource given in %s on line %d
206bool(false)
207Done
208