Annotation of embedaddon/php/ext/mbstring/tests/mb_strrichr_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test mb_strrichr() function : usage variation - different types of needle.
3: --SKIPIF--
4: <?php
5: extension_loaded('mbstring') or die('skip');
6: function_exists('mb_strrichr') or die("skip mb_strrichr() is not available in this build");
7: ?>
8: --FILE--
9: <?php
10: /* Prototype : string mb_strrichr(string haystack, string needle[, bool part[, string encoding]])
11: * Description: Finds the last occurrence of a character in a string within another, case insensitive
12: * Source code: ext/mbstring/mbstring.c
13: * Alias to functions:
14: */
15:
16: echo "*** Testing mb_strrichr() : usage variation ***\n";
17:
18: // Define error handler
19: function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
20: if (error_reporting() != 0) {
21: // report non-silenced errors
22: echo "Error: $err_no - $err_msg, $filename($linenum)\n";
23: }
24: }
25: set_error_handler('test_error_handler');
26:
27: // Initialise function arguments not being substituted (if any)
28: $haystack = b'string_val';
29: $part = true;
30: $encoding = 'utf-8';
31:
32: //get an unset variable
33: $unset_var = 10;
34: unset ($unset_var);
35:
36: // define some classes
37: class classWithToString
38: {
39: public function __toString() {
40: return b"Class A object";
41: }
42: }
43:
44: class classWithoutToString
45: {
46: }
47:
48: // heredoc string
49: $heredoc = b<<<EOT
50: hello world
51: EOT;
52:
53: // get a resource variable
54: $fp = fopen(__FILE__, "r");
55:
56: // add arrays
57: $index_array = array (1, 2, 3);
58: $assoc_array = array ('one' => 1, 'two' => 2);
59:
60: //array of values to iterate over
61: $inputs = array(
62:
63: // int data
64: 'int 0' => 0,
65: 'int 1' => 1,
66: 'int 12345' => 12345,
67: 'int -12345' => -2345,
68:
69: // float data
70: 'float 10.5' => 10.5,
71: 'float -10.5' => -10.5,
72: 'float 12.3456789000e10' => 12.3456789000e10,
73: 'float -12.3456789000e10' => -12.3456789000e10,
74: 'float .5' => .5,
75:
76: // array data
77: 'empty array' => array(),
78: 'int indexed array' => $index_array,
79: 'associative array' => $assoc_array,
80: 'nested arrays' => array('foo', $index_array, $assoc_array),
81:
82: // null data
83: 'uppercase NULL' => NULL,
84: 'lowercase null' => null,
85:
86: // boolean data
87: 'lowercase true' => true,
88: 'lowercase false' =>false,
89: 'uppercase TRUE' =>TRUE,
90: 'uppercase FALSE' =>FALSE,
91:
92: // empty data
93: 'empty string DQ' => "",
94: 'empty string SQ' => '',
95:
96: // object data
97: 'instance of classWithToString' => new classWithToString(),
98: 'instance of classWithoutToString' => new classWithoutToString(),
99:
100: // undefined data
101: 'undefined var' => @$undefined_var,
102:
103: // unset data
104: 'unset var' => @$unset_var,
105:
106: // resource variable
107: 'resource' => $fp
108: );
109:
110: // loop through each element of the array for needle
111:
112: foreach($inputs as $key =>$value) {
113: echo "\n--$key--\n";
114: var_dump( mb_strrichr($haystack, $value, $part, $encoding) );
115: };
116:
117: fclose($fp);
118:
119: ?>
120: ===DONE===
121: --EXPECTF--
122: *** Testing mb_strrichr() : usage variation ***
123:
124: --int 0--
125: bool(false)
126:
127: --int 1--
128: bool(false)
129:
130: --int 12345--
131: bool(false)
132:
133: --int -12345--
134: bool(false)
135:
136: --float 10.5--
137: bool(false)
138:
139: --float -10.5--
140: bool(false)
141:
142: --float 12.3456789000e10--
143: bool(false)
144:
145: --float -12.3456789000e10--
146: bool(false)
147:
148: --float .5--
149: bool(false)
150:
151: --empty array--
152: Error: 2 - mb_strrichr() expects parameter 2 to be string, array given, %s(%d)
153: bool(false)
154:
155: --int indexed array--
156: Error: 2 - mb_strrichr() expects parameter 2 to be string, array given, %s(%d)
157: bool(false)
158:
159: --associative array--
160: Error: 2 - mb_strrichr() expects parameter 2 to be string, array given, %s(%d)
161: bool(false)
162:
163: --nested arrays--
164: Error: 2 - mb_strrichr() expects parameter 2 to be string, array given, %s(%d)
165: bool(false)
166:
167: --uppercase NULL--
168: bool(false)
169:
170: --lowercase null--
171: bool(false)
172:
173: --lowercase true--
174: bool(false)
175:
176: --lowercase false--
177: bool(false)
178:
179: --uppercase TRUE--
180: bool(false)
181:
182: --uppercase FALSE--
183: bool(false)
184:
185: --empty string DQ--
186: bool(false)
187:
188: --empty string SQ--
189: bool(false)
190:
191: --instance of classWithToString--
192: bool(false)
193:
194: --instance of classWithoutToString--
195: Error: 2 - mb_strrichr() expects parameter 2 to be string, object given, %s(%d)
196: bool(false)
197:
198: --undefined var--
199: bool(false)
200:
201: --unset var--
202: bool(false)
203:
204: --resource--
205: Error: 2 - mb_strrichr() expects parameter 2 to be string, resource given, %s(%d)
206: bool(false)
207: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>