1--TEST--
2Test mb_strrichr() function : usage variation - different values for part
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_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
16echo "*** Testing mb_strrichr() : usage variation ***\n";
17
18// Define error handler
19function 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}
25set_error_handler('test_error_handler');
26
27// Initialise function arguments not being substituted (if any)
28$haystack = 'string_val';
29$needle = '_';
30$encoding = 'utf-8';
31
32//get an unset variable
33$unset_var = 10;
34unset ($unset_var);
35
36// define some classes
37class classWithToString
38{
39	public function __toString() {
40		return "Class A object";
41	}
42}
43
44class classWithoutToString
45{
46}
47
48// heredoc string
49$heredoc = <<<EOT
50hello world
51EOT;
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      // string data
97      'string DQ' => "string",
98      'string SQ' => 'string',
99      'mixed case string' => "sTrInG",
100      'heredoc' => $heredoc,
101
102      // object data
103      'instance of classWithToString' => new classWithToString(),
104      'instance of classWithoutToString' => new classWithoutToString(),
105
106      // undefined data
107      'undefined var' => @$undefined_var,
108
109      // unset data
110      'unset var' => @$unset_var,
111
112      // resource variable
113      'resource' => $fp
114);
115
116// loop through each element of the array for part
117
118foreach($inputs as $key =>$value) {
119      echo "\n--$key--\n";
120      $res = mb_strrichr($haystack, $needle, $value, $encoding);
121      if ($res === NULL) {
122         var_dump($res);
123      }
124      else {
125         var_dump(bin2hex($res));
126      }
127};
128
129fclose($fp);
130
131?>
132===DONE===
133--EXPECTF--
134*** Testing mb_strrichr() : usage variation ***
135
136--int 0--
137string(8) "5f76616c"
138
139--int 1--
140string(12) "737472696e67"
141
142--int 12345--
143string(12) "737472696e67"
144
145--int -12345--
146string(12) "737472696e67"
147
148--float 10.5--
149string(12) "737472696e67"
150
151--float -10.5--
152string(12) "737472696e67"
153
154--float 12.3456789000e10--
155string(12) "737472696e67"
156
157--float -12.3456789000e10--
158string(12) "737472696e67"
159
160--float .5--
161string(12) "737472696e67"
162
163--empty array--
164Error: 2 - mb_strrichr() expects parameter 3 to be boolean, array given, %s(%d)
165NULL
166
167--int indexed array--
168Error: 2 - mb_strrichr() expects parameter 3 to be boolean, array given, %s(%d)
169NULL
170
171--associative array--
172Error: 2 - mb_strrichr() expects parameter 3 to be boolean, array given, %s(%d)
173NULL
174
175--nested arrays--
176Error: 2 - mb_strrichr() expects parameter 3 to be boolean, array given, %s(%d)
177NULL
178
179--uppercase NULL--
180string(8) "5f76616c"
181
182--lowercase null--
183string(8) "5f76616c"
184
185--lowercase true--
186string(12) "737472696e67"
187
188--lowercase false--
189string(8) "5f76616c"
190
191--uppercase TRUE--
192string(12) "737472696e67"
193
194--uppercase FALSE--
195string(8) "5f76616c"
196
197--empty string DQ--
198string(8) "5f76616c"
199
200--empty string SQ--
201string(8) "5f76616c"
202
203--string DQ--
204string(12) "737472696e67"
205
206--string SQ--
207string(12) "737472696e67"
208
209--mixed case string--
210string(12) "737472696e67"
211
212--heredoc--
213string(12) "737472696e67"
214
215--instance of classWithToString--
216Error: 2 - mb_strrichr() expects parameter 3 to be boolean, object given, %s(%d)
217NULL
218
219--instance of classWithoutToString--
220Error: 2 - mb_strrichr() expects parameter 3 to be boolean, object given, %s(%d)
221NULL
222
223--undefined var--
224string(8) "5f76616c"
225
226--unset var--
227string(8) "5f76616c"
228
229--resource--
230Error: 2 - mb_strrichr() expects parameter 3 to be boolean, resource given, %s(%d)
231NULL
232===DONE===
233