1--TEST--
2Test iconv_strpos() function : usage variations - pass different data types as $needle 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 * Pass iconv_strpos different data types as $needle arg to test behaviour
17 */
18
19echo "*** Testing iconv_strpos() : usage variations ***\n";
20
21// Initialise function arguments not being substituted
22$haystack = 'string_val';
23$offset = 0;
24$encoding = 'utf-8';
25
26//get an unset variable
27$unset_var = 10;
28unset ($unset_var);
29
30// get a class
31class classA
32{
33  public function __toString() {
34    return "Class A object";
35  }
36}
37
38// heredoc string
39$heredoc = <<<EOT
40hello world
41EOT;
42
43// get a resource variable
44$fp = fopen(__FILE__, "r");
45
46// unexpected values to be passed to $needle argument
47$inputs = array(
48
49       // int data
50/*1*/  0,
51       1,
52       12345,
53       -2345,
54
55       // float data
56/*5*/  10.5,
57       -10.5,
58       12.3456789000e10,
59       12.3456789000E-10,
60       .5,
61
62       // null data
63/*10*/ NULL,
64       null,
65
66       // boolean data
67/*12*/ true,
68       false,
69       TRUE,
70       FALSE,
71
72       // empty data
73/*16*/ "",
74       '',
75
76       // string data
77/*18*/ "string",
78       'string',
79       $heredoc,
80
81       // object data
82/*21*/ new classA(),
83
84       // undefined data
85/*22*/ @$undefined_var,
86
87       // unset data
88/*23*/ @$unset_var,
89
90       // resource variable
91/*24*/ $fp
92);
93
94// loop through each element of $inputs to check the behavior of iconv_strpos()
95$iterator = 1;
96foreach($inputs as $input) {
97  echo "\n-- Iteration $iterator --\n";
98  var_dump( iconv_strpos($haystack, $input, $offset, $encoding));
99  $iterator++;
100};
101
102fclose($fp);
103
104echo "Done";
105?>
106--EXPECTF--
107*** Testing iconv_strpos() : usage variations ***
108
109-- Iteration 1 --
110bool(false)
111
112-- Iteration 2 --
113bool(false)
114
115-- Iteration 3 --
116bool(false)
117
118-- Iteration 4 --
119bool(false)
120
121-- Iteration 5 --
122bool(false)
123
124-- Iteration 6 --
125bool(false)
126
127-- Iteration 7 --
128bool(false)
129
130-- Iteration 8 --
131bool(false)
132
133-- Iteration 9 --
134bool(false)
135
136-- Iteration 10 --
137bool(false)
138
139-- Iteration 11 --
140bool(false)
141
142-- Iteration 12 --
143bool(false)
144
145-- Iteration 13 --
146bool(false)
147
148-- Iteration 14 --
149bool(false)
150
151-- Iteration 15 --
152bool(false)
153
154-- Iteration 16 --
155bool(false)
156
157-- Iteration 17 --
158bool(false)
159
160-- Iteration 18 --
161int(0)
162
163-- Iteration 19 --
164int(0)
165
166-- Iteration 20 --
167bool(false)
168
169-- Iteration 21 --
170bool(false)
171
172-- Iteration 22 --
173bool(false)
174
175-- Iteration 23 --
176bool(false)
177
178-- Iteration 24 --
179
180Warning: iconv_strpos() expects parameter 2 to be string, resource given in %s on line %d
181bool(false)
182Done
183