Annotation of embedaddon/php/ext/standard/tests/strings/stripos_variation14.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test 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:
12: echo "*** Testing stripos() function with unexpected values for offset ***\n";
13:
14: // get an unset variable
15: $unset_var = 'string_val';
16: unset($unset_var);
17:
18: // defining a class
19: class 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;
79: for($index = 0; $index < count($offsets); $index ++) {
80: echo "-- Iteration $counter --\n";
81: var_dump( stripos($haystack, $needle, $offsets[$index]) );
82: $counter ++;
83: }
84:
85: echo "*** Done ***";
86: ?>
87: --EXPECTF--
88: *** Testing stripos() function with unexpected values for offset ***
89: -- Iteration 1 --
90: int(6)
91: -- Iteration 2 --
92:
93: Warning: stripos(): Offset not contained in string in %s on line %d
94: bool(false)
95: -- Iteration 3 --
96:
97: Warning: stripos(): Offset not contained in string in %s on line %d
98: bool(false)
99: -- Iteration 4 --
100: int(6)
101: -- Iteration 5 --
102: int(6)
103: -- Iteration 6 --
104:
105: Warning: stripos() expects parameter 3 to be long, array given in %s on line %d
106: NULL
107: -- Iteration 7 --
108:
109: Warning: stripos() expects parameter 3 to be long, array given in %s on line %d
110: NULL
111: -- Iteration 8 --
112:
113: Warning: stripos() expects parameter 3 to be long, array given in %s on line %d
114: NULL
115: -- Iteration 9 --
116:
117: Warning: stripos() expects parameter 3 to be long, array given in %s on line %d
118: NULL
119: -- Iteration 10 --
120:
121: Warning: stripos() expects parameter 3 to be long, array given in %s on line %d
122: NULL
123: -- Iteration 11 --
124: int(6)
125: -- Iteration 12 --
126: int(6)
127: -- Iteration 13 --
128: int(6)
129: -- Iteration 14 --
130: int(6)
131: -- Iteration 15 --
132:
133: Warning: stripos() expects parameter 3 to be long, object given in %s on line %d
134: NULL
135: -- Iteration 16 --
136:
137: Warning: stripos() expects parameter 3 to be long, string given in %s on line %d
138: NULL
139: -- Iteration 17 --
140:
141: Warning: stripos() expects parameter 3 to be long, string given in %s on line %d
142: NULL
143: -- Iteration 18 --
144: int(6)
145: -- Iteration 19 --
146: int(6)
147: -- Iteration 20 --
148:
149: Warning: stripos() expects parameter 3 to be long, resource given in %s on line %d
150: NULL
151: -- Iteration 21 --
152: int(6)
153: -- Iteration 22 --
154: int(6)
155: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>