1--TEST--
2Test mb_strrpos() function : usage variations - Pass different data types to $needle arg
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
11 * Description: Find position of last occurrence of a string within another
12 * Source code: ext/mbstring/mbstring.c
13 */
14
15/*
16 * Pass mb_strrpos() different data types as $needle argument to test behaviour
17 */
18
19echo "*** Testing mb_strrpos() : usage variations ***\n";
20
21// Initialise function arguments not being substituted
22$haystack = 'hello, world';
23$offset = 0;
24$encoding = 'utf-8';
25
26//get an unset variable
27$unset_var = 10;
28unset ($unset_var);
29
30// get a class
31class classA
32{
33  public function __toString() {
34    return "world";
35  }
36}
37
38// heredoc string
39$heredoc = <<<EOT
40world
41EOT;
42
43// get a resource variable
44$fp = fopen(__FILE__, "r");
45
46// unexpected values to be passed to $needle argument
47$inputs = array(
48
49       // int data
50/*1*/  0,
51       1,
52       12345,
53       -2345,
54
55       // float data
56/*5*/  10.5,
57       -10.5,
58       12.3456789000e10,
59       12.3456789000E-10,
60       .5,
61
62       // null data
63/*10*/ NULL,
64       null,
65
66       // boolean data
67/*12*/ true,
68       false,
69       TRUE,
70       FALSE,
71
72       // empty data
73/*16*/ "",
74       '',
75
76       // string data
77/*18*/ "world",
78       'world',
79       $heredoc,
80
81       // object data
82/*21*/ new classA(),
83
84       // undefined data
85/*22*/ @$undefined_var,
86
87       // unset data
88/*23*/ @$unset_var,
89
90       // resource variable
91/*24*/ $fp
92);
93
94// loop through each element of $inputs to check the behavior of mb_strrpos()
95$iterator = 1;
96foreach($inputs as $input) {
97  echo "\n-- Iteration $iterator --\n";
98  var_dump( mb_strrpos($haystack, $input, $offset, $encoding));
99  $iterator++;
100};
101
102fclose($fp);
103
104echo "Done";
105?>
106
107--EXPECTF--
108*** Testing mb_strrpos() : usage variations ***
109
110-- Iteration 1 --
111bool(false)
112
113-- Iteration 2 --
114bool(false)
115
116-- Iteration 3 --
117bool(false)
118
119-- Iteration 4 --
120bool(false)
121
122-- Iteration 5 --
123bool(false)
124
125-- Iteration 6 --
126bool(false)
127
128-- Iteration 7 --
129bool(false)
130
131-- Iteration 8 --
132bool(false)
133
134-- Iteration 9 --
135bool(false)
136
137-- Iteration 10 --
138bool(false)
139
140-- Iteration 11 --
141bool(false)
142
143-- Iteration 12 --
144bool(false)
145
146-- Iteration 13 --
147bool(false)
148
149-- Iteration 14 --
150bool(false)
151
152-- Iteration 15 --
153bool(false)
154
155-- Iteration 16 --
156bool(false)
157
158-- Iteration 17 --
159bool(false)
160
161-- Iteration 18 --
162int(7)
163
164-- Iteration 19 --
165int(7)
166
167-- Iteration 20 --
168int(7)
169
170-- Iteration 21 --
171int(7)
172
173-- Iteration 22 --
174bool(false)
175
176-- Iteration 23 --
177bool(false)
178
179-- Iteration 24 --
180
181Warning: mb_strrpos() expects parameter 2 to be string, resource given in %s on line %d
182bool(false)
183Done
184