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