Annotation of embedaddon/php/ext/standard/tests/strings/strrpos_variation11.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test strrpos() function : usage variations - unexpected inputs for 'haystack' and 'needle' arguments
3: --FILE--
4: <?php
5: /* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] );
6: * Description: Find position of last occurrence of 'needle' in 'haystack'.
7: * Source code: ext/standard/string.c
8: */
9:
10: /* Test strrpos() function with unexpected inputs for 'haystack' and 'needle' arguments */
11:
12: echo "*** Testing strrpos() function with unexpected values for haystack and needle ***\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: // array with different values
29: $values = array (
30:
31: // integer values
32: 0,
33: 1,
34: 12345,
35: -2345,
36:
37: // float values
38: 10.5,
39: -10.5,
40: 10.5e10,
41: 10.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 strrpos()
80: $counter = 1;
81: for($index = 0; $index < count($values); $index ++) {
82: echo "-- Iteration $counter --\n";
83: $haystack = $values[$index];
84: var_dump( strrpos($values[$index], $values[$index]) );
85: var_dump( strrpos($values[$index], $values[$index], 1) );
86: $counter ++;
87: }
88:
89: echo "*** Done ***";
90: ?>
91: --EXPECTF--
92: *** Testing strrpos() function with unexpected values for haystack and needle ***
93: -- Iteration 1 --
94: bool(false)
95: bool(false)
96: -- Iteration 2 --
97: bool(false)
98: bool(false)
99: -- Iteration 3 --
100: bool(false)
101: bool(false)
102: -- Iteration 4 --
103: bool(false)
104: bool(false)
105: -- Iteration 5 --
106: bool(false)
107: bool(false)
108: -- Iteration 6 --
109: bool(false)
110: bool(false)
111: -- Iteration 7 --
112: bool(false)
113: bool(false)
114: -- Iteration 8 --
115: bool(false)
116: bool(false)
117: -- Iteration 9 --
118: bool(false)
119: bool(false)
120: -- Iteration 10 --
121:
122: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
123: bool(false)
124:
125: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
126: bool(false)
127: -- Iteration 11 --
128:
129: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
130: bool(false)
131:
132: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
133: bool(false)
134: -- Iteration 12 --
135:
136: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
137: bool(false)
138:
139: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
140: bool(false)
141: -- Iteration 13 --
142:
143: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
144: bool(false)
145:
146: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
147: bool(false)
148: -- Iteration 14 --
149:
150: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
151: bool(false)
152:
153: Warning: strrpos() expects parameter 1 to be string, array given in %s on line %d
154: bool(false)
155: -- Iteration 15 --
156: bool(false)
157: bool(false)
158: -- Iteration 16 --
159: bool(false)
160: bool(false)
161: -- Iteration 17 --
162: bool(false)
163: bool(false)
164: -- Iteration 18 --
165: bool(false)
166: bool(false)
167: -- Iteration 19 --
168:
169: Notice: Object of class sample could not be converted to int in %s on line %d
170: bool(false)
171:
172: Notice: Object of class sample could not be converted to int in %s on line %d
173: bool(false)
174: -- Iteration 20 --
175: bool(false)
176: bool(false)
177: -- Iteration 21 --
178: bool(false)
179: bool(false)
180: -- Iteration 22 --
181: bool(false)
182: bool(false)
183: -- Iteration 23 --
184: bool(false)
185: bool(false)
186: -- Iteration 24 --
187:
188: Warning: strrpos() expects parameter 1 to be string, resource given in %s on line %d
189: bool(false)
190:
191: Warning: strrpos() expects parameter 1 to be string, resource given in %s on line %d
192: bool(false)
193: -- Iteration 25 --
194: bool(false)
195: bool(false)
196: -- Iteration 26 --
197: bool(false)
198: bool(false)
199: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>