1--TEST--
2Test stripos() function : usage variations - unexpected inputs for 'offset' argument
3--SKIPIF--
4<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64-bit only");
5--FILE--
6<?php
7/* Prototype  : int stripos ( string $haystack, string $needle [, int $offset] );
8 * Description: Find position of first occurrence of a case-insensitive string
9 * Source code: ext/standard/string.c
10*/
11
12/* Test stripos() function with unexpected inputs for 'offset' argument */
13
14echo "*** Testing stripos() function with unexpected values for offset ***\n";
15
16// get an unset variable
17$unset_var = 'string_val';
18unset($unset_var);
19
20// defining a class
21class sample  {
22  public function __toString() {
23    return "object";
24  }
25}
26
27//getting the resource
28$file_handle = fopen(__FILE__, "r");
29
30//definition of input args
31$haystack = "hello world";
32$needle = "world";
33
34// array with different values
35$offsets =  array (
36
37  // float values
38  1.5,
39  -1.5,
40  1.5e10,
41  1.6E-10,
42  .5,
43
44  // array values
45  array(),
46  array(0),
47  array(1),
48  array(1, 2),
49  array('color' => 'red', 'item' => 'pen'),
50
51  // boolean values
52  true,
53  false,
54  TRUE,
55  FALSE,
56
57  // objects
58  new sample(),
59
60  // empty string
61  "",
62  '',
63
64  // null vlaues
65  NULL,
66  null,
67
68  //resource
69  $file_handle,
70
71  // undefined variable
72  @$undefined_var,
73
74  // unset variable
75  @$unset_var
76);
77
78
79// loop through each element of the array and check the working of stripos()
80$counter = 1;
81for($index = 0; $index < count($offsets); $index ++) {
82  echo "-- Iteration $counter --\n";
83  var_dump( stripos($haystack, $needle, $offsets[$index]) );
84  $counter ++;
85}
86
87echo "*** Done ***";
88?>
89--EXPECTF--
90*** Testing stripos() function with unexpected values for offset ***
91-- Iteration 1 --
92int(6)
93-- Iteration 2 --
94
95Warning: stripos(): Offset not contained in string in %s on line %d
96bool(false)
97-- Iteration 3 --
98
99Warning: stripos(): Offset not contained in string in %s on line %d
100bool(false)
101-- Iteration 4 --
102int(6)
103-- Iteration 5 --
104int(6)
105-- Iteration 6 --
106
107Warning: stripos() expects parameter 3 to be integer, array given in %s on line %d
108NULL
109-- Iteration 7 --
110
111Warning: stripos() expects parameter 3 to be integer, array given in %s on line %d
112NULL
113-- Iteration 8 --
114
115Warning: stripos() expects parameter 3 to be integer, array given in %s on line %d
116NULL
117-- Iteration 9 --
118
119Warning: stripos() expects parameter 3 to be integer, array given in %s on line %d
120NULL
121-- Iteration 10 --
122
123Warning: stripos() expects parameter 3 to be integer, array given in %s on line %d
124NULL
125-- Iteration 11 --
126int(6)
127-- Iteration 12 --
128int(6)
129-- Iteration 13 --
130int(6)
131-- Iteration 14 --
132int(6)
133-- Iteration 15 --
134
135Warning: stripos() expects parameter 3 to be integer, object given in %s on line %d
136NULL
137-- Iteration 16 --
138
139Warning: stripos() expects parameter 3 to be integer, string given in %s on line %d
140NULL
141-- Iteration 17 --
142
143Warning: stripos() expects parameter 3 to be integer, string given in %s on line %d
144NULL
145-- Iteration 18 --
146int(6)
147-- Iteration 19 --
148int(6)
149-- Iteration 20 --
150
151Warning: stripos() expects parameter 3 to be integer, resource given in %s on line %d
152NULL
153-- Iteration 21 --
154int(6)
155-- Iteration 22 --
156int(6)
157*** Done ***
158