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