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