1--TEST--
2Test stripos() function : usage variations - unexpected inputs for 'haystack', 'needle' & 'offset' arguments
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 'haystack', 'needle' & 'offset' arguments */
13
14echo "*** Testing stripos() function with unexpected values for haystack, needle & 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// array with different values
31$values =  array (
32
33  // integer values
34  0,
35  1,
36  12345,
37  -2345,
38
39  // float values
40  10.5,
41  -10.5,
42  10.5e10,
43  10.6E-10,
44  .5,
45
46  // array values
47  array(),
48  array(0),
49  array(1),
50  array(1, 2),
51  array('color' => 'red', 'item' => 'pen'),
52
53  // boolean values
54  true,
55  false,
56  TRUE,
57  FALSE,
58
59  // objects
60  new sample(),
61
62  // empty string
63  "",
64  '',
65
66  // null vlaues
67  NULL,
68  null,
69
70  //resource
71  $file_handle,
72
73  // undefined variable
74  @$undefined_var,
75
76  // unset variable
77  @$unset_var
78);
79
80
81// loop through each element of the array and check the working of stripos()
82$counter = 1;
83for($index = 0; $index < count($values); $index ++) {
84  echo "-- Iteration $counter --\n";
85  var_dump( stripos($values[$index], $values[$index], $values[$index]) );
86  $counter ++;
87}
88
89echo "*** Done ***";
90?>
91--EXPECTF--
92*** Testing stripos() function with unexpected values for haystack, needle & offset ***
93-- Iteration 1 --
94bool(false)
95-- Iteration 2 --
96bool(false)
97-- Iteration 3 --
98
99Warning: stripos(): Offset not contained in string in %s on line %d
100bool(false)
101-- Iteration 4 --
102
103Warning: stripos(): Offset not contained in string in %s on line %d
104bool(false)
105-- Iteration 5 --
106
107Warning: stripos(): Offset not contained in string in %s on line %d
108bool(false)
109-- Iteration 6 --
110
111Warning: stripos(): Offset not contained in string in %s on line %d
112bool(false)
113-- Iteration 7 --
114
115Warning: stripos(): Offset not contained in string in %s on line %d
116bool(false)
117-- Iteration 8 --
118bool(false)
119-- Iteration 9 --
120bool(false)
121-- Iteration 10 --
122
123Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
124NULL
125-- Iteration 11 --
126
127Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
128NULL
129-- Iteration 12 --
130
131Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
132NULL
133-- Iteration 13 --
134
135Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
136NULL
137-- Iteration 14 --
138
139Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
140NULL
141-- Iteration 15 --
142bool(false)
143-- Iteration 16 --
144bool(false)
145-- Iteration 17 --
146bool(false)
147-- Iteration 18 --
148bool(false)
149-- Iteration 19 --
150
151Warning: stripos() expects parameter 3 to be integer, object given in %s on line %d
152NULL
153-- Iteration 20 --
154
155Warning: stripos() expects parameter 3 to be integer, string given in %s on line %d
156NULL
157-- Iteration 21 --
158
159Warning: stripos() expects parameter 3 to be integer, string given in %s on line %d
160NULL
161-- Iteration 22 --
162bool(false)
163-- Iteration 23 --
164bool(false)
165-- Iteration 24 --
166
167Warning: stripos() expects parameter 1 to be string, resource given in %s on line %d
168NULL
169-- Iteration 25 --
170bool(false)
171-- Iteration 26 --
172bool(false)
173*** Done ***
174