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