Annotation of embedaddon/php/ext/standard/tests/strings/strrchr_variation9.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test strrchr() function : usage variations - unexpected inputs for haystack
3: --FILE--
4: <?php
5: /* Prototype : string strrchr(string $haystack, string $needle);
6: * Description: Finds the last occurrence of a character in a string.
7: * Source code: ext/standard/string.c
8: */
9:
10: /* Test strrchr() function with unexpected inputs for haystack
11: * and expected type for 'needle'
12: */
13:
14: echo "*** Testing strrchr() function: with unexpected inputs for haystack ***\n";
15:
16: // get an unset variable
17: $unset_var = 'string_val';
18: unset($unset_var);
19:
20: // declaring a class
21: class 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: $haystacks = 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: // null vlaues
60: NULL,
61: null,
62:
63: // objects
64: new sample(),
65:
66: // empty string
67: "",
68: '',
69:
70: // resource
71: $file_handle,
72:
73: // undefined variable
74: @$undefined_var,
75:
76: // unset variable
77: @$unset_var
78: );
79:
80: $needles = array (
81: //integer numeric strings
82: "0",
83: "1",
84: "2",
85: "-2",
86:
87: //float numeric strings
88: "10.5",
89: "-10.5",
90: "10.5e10",
91: "10.6E-10",
92: ".5",
93:
94: //regular strings
95: "array",
96: "a",
97: "r",
98: "y",
99: "ay",
100: "true",
101: "false",
102: "TRUE",
103: "FALSE",
104: "NULL",
105: "null",
106: "object",
107:
108: //empty string
109: "",
110: '',
111:
112: //resource variable in string form
113: "\$file_handle",
114:
115: //undefined variable in string form
116: @"$undefined_var",
117: @"$unset_var"
118: );
119:
120: // loop through each element of the array and check the working of strrchr()
121: $count = 1;
122: for($index = 0; $index < count($haystacks); $index++) {
123: echo "-- Iteration $count --\n";
124: var_dump( strrchr($haystacks[$index], $needles[$index]) );
125: $count ++;
126: }
127:
128: fclose($file_handle); //closing the file handle
129:
130: echo "*** Done ***";
131: ?>
132: --EXPECTF--
133: *** Testing strrchr() function: with unexpected inputs for haystack ***
134: -- Iteration 1 --
135: string(1) "0"
136: -- Iteration 2 --
137: string(1) "1"
138: -- Iteration 3 --
139: string(4) "2345"
140: -- Iteration 4 --
141: string(5) "-2345"
142: -- Iteration 5 --
143: string(4) "10.5"
144: -- Iteration 6 --
145: string(5) "-10.5"
146: -- Iteration 7 --
147: string(12) "105000000000"
148: -- Iteration 8 --
149: string(7) "1.06E-9"
150: -- Iteration 9 --
151: string(2) ".5"
152: -- Iteration 10 --
153:
154: Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d
155: NULL
156: -- Iteration 11 --
157:
158: Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d
159: NULL
160: -- Iteration 12 --
161:
162: Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d
163: NULL
164: -- Iteration 13 --
165:
166: Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d
167: NULL
168: -- Iteration 14 --
169:
170: Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d
171: NULL
172: -- Iteration 15 --
173: bool(false)
174: -- Iteration 16 --
175: bool(false)
176: -- Iteration 17 --
177: bool(false)
178: -- Iteration 18 --
179: bool(false)
180: -- Iteration 19 --
181: bool(false)
182: -- Iteration 20 --
183: bool(false)
184: -- Iteration 21 --
185: string(6) "object"
186: -- Iteration 22 --
187: bool(false)
188: -- Iteration 23 --
189: bool(false)
190: -- Iteration 24 --
191:
192: Warning: strrchr() expects parameter 1 to be string, resource given in %s on line %d
193: NULL
194: -- Iteration 25 --
195: bool(false)
196: -- Iteration 26 --
197: bool(false)
198: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>