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 = 'string_val';
25$needle = '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--EXPECTF--
109*** Testing iconv_strpos() : usage variations ***
110
111-- Iteration 1 --
112
113Notice: iconv_strpos(): Wrong charset, conversion from `0' to `UCS-4LE' is not allowed in %s on line %d
114bool(false)
115
116-- Iteration 2 --
117
118Notice: iconv_strpos(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d
119bool(false)
120
121-- Iteration 3 --
122
123Notice: iconv_strpos(): Wrong charset, conversion from `12345' to `UCS-4LE' is not allowed in %s on line %d
124bool(false)
125
126-- Iteration 4 --
127
128Notice: iconv_strpos(): Wrong charset, conversion from `-2345' to `UCS-4LE' is not allowed in %s on line %d
129bool(false)
130
131-- Iteration 5 --
132
133Notice: iconv_strpos(): Wrong charset, conversion from `10.5' to `UCS-4LE' is not allowed in %s on line %d
134bool(false)
135
136-- Iteration 6 --
137
138Notice: iconv_strpos(): Wrong charset, conversion from `-10.5' to `UCS-4LE' is not allowed in %s on line %d
139bool(false)
140
141-- Iteration 7 --
142
143Notice: iconv_strpos(): Wrong charset, conversion from `123456789000' to `UCS-4LE' is not allowed in %s on line %d
144bool(false)
145
146-- Iteration 8 --
147
148Notice: iconv_strpos(): Wrong charset, conversion from `1.23456789E-9' to `UCS-4LE' is not allowed in %s on line %d
149bool(false)
150
151-- Iteration 9 --
152
153Notice: iconv_strpos(): Wrong charset, conversion from `0.5' to `UCS-4LE' is not allowed in %s on line %d
154bool(false)
155
156-- Iteration 10 --
157int(7)
158
159-- Iteration 11 --
160int(7)
161
162-- Iteration 12 --
163
164Notice: iconv_strpos(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d
165bool(false)
166
167-- Iteration 13 --
168int(7)
169
170-- Iteration 14 --
171
172Notice: iconv_strpos(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d
173bool(false)
174
175-- Iteration 15 --
176int(7)
177
178-- Iteration 16 --
179int(7)
180
181-- Iteration 17 --
182int(7)
183
184-- Iteration 18 --
185int(7)
186
187-- Iteration 19 --
188int(7)
189
190-- Iteration 20 --
191int(7)
192
193-- Iteration 21 --
194int(7)
195
196-- Iteration 22 --
197int(7)
198
199-- Iteration 23 --
200int(7)
201
202-- Iteration 24 --
203
204Warning: iconv_strpos() expects parameter 4 to be string, resource given in %s on line %d
205bool(false)
206Done
207