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