Annotation of embedaddon/php/ext/standard/tests/strings/strrchr_variation10.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test strrchr() function : usage variations - unexpected inputs for needle
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 needle
11: * and expected type for haystack
12: */
13:
14: echo "*** Testing strrchr() function with unexpected inputs for needle ***\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: $haystacks = array (
31: //integer numeric strings
32: "0",
33: "1",
34: "2",
35: "-2",
36:
37: //float numeric strings
38: "10.5",
39: "-10.5",
40: "10.5e10",
41: "10.6E-10",
42: ".5",
43:
44: //regular strings
45: "array",
46: "a",
47: "r",
48: "y",
49: "ay",
50: "true",
51: "false",
52: "TRUE",
53: "FALSE",
54: "NULL",
55: "null",
56: "object",
57:
58: //empty string
59: "",
60: '',
61:
62: //resource variable in string form
63: "\$file_handle",
64:
65: //undefined variable in string form
66: @"$undefined_var",
67: @"$unset_var"
68: );
69:
70: // array with different values
71: $needles = array (
72:
73: // integer values
74: 0,
75: 1,
76: 12345,
77: -2345,
78:
79: // float values
80: 10.5,
81: -10.5,
82: 10.1234567e10,
83: 10.7654321E-10,
84: .5,
85:
86: // array values
87: array(),
88: array(0),
89: array(1),
90: array(1, 2),
91: array('color' => 'red', 'item' => 'pen'),
92:
93: // boolean values
94: true,
95: false,
96: TRUE,
97: FALSE,
98:
99: // null vlaues
100: NULL,
101: null,
102:
103: // objects
104: new sample(),
105:
106: // empty string
107: "",
108: '',
109:
110: // resource
111: $file_handle,
112:
113: // undefined variable
114: @$undefined_var,
115:
116: // unset variable
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 needle ***
134: -- Iteration 1 --
135: bool(false)
136: -- Iteration 2 --
137: bool(false)
138: -- Iteration 3 --
139: bool(false)
140: -- Iteration 4 --
141: bool(false)
142: -- Iteration 5 --
143: bool(false)
144: -- Iteration 6 --
145: bool(false)
146: -- Iteration 7 --
147: bool(false)
148: -- Iteration 8 --
149: bool(false)
150: -- Iteration 9 --
151: bool(false)
152: -- Iteration 10 --
153:
154: Warning: strrchr(): needle is not a string or an integer in %s on line %d
155: bool(false)
156: -- Iteration 11 --
157:
158: Warning: strrchr(): needle is not a string or an integer in %s on line %d
159: bool(false)
160: -- Iteration 12 --
161:
162: Warning: strrchr(): needle is not a string or an integer in %s on line %d
163: bool(false)
164: -- Iteration 13 --
165:
166: Warning: strrchr(): needle is not a string or an integer in %s on line %d
167: bool(false)
168: -- Iteration 14 --
169:
170: Warning: strrchr(): needle is not a string or an integer in %s on line %d
171: bool(false)
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:
186: Notice: Object of class sample could not be converted to int in %s on line %d
187: bool(false)
188: -- Iteration 22 --
189: bool(false)
190: -- Iteration 23 --
191: bool(false)
192: -- Iteration 24 --
193:
194: Warning: strrchr(): needle is not a string or an integer in %s on line %d
195: bool(false)
196: -- Iteration 25 --
197: bool(false)
198: -- Iteration 26 --
199: bool(false)
200: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>