1--TEST--
2Test iconv_strrpos() function : usage variations - pass different data types to $haystack 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 $haystack argument to test behaviour
17 */
18
19echo "*** Testing iconv_strrpos() : usage variations ***\n";
20
21// Initialise function arguments not being substituted
22$needle = '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 "hello, world";
34  }
35}
36
37// heredoc string
38$heredoc = <<<EOT
39hello, world
40EOT;
41
42// get a resource variable
43$fp = fopen(__FILE__, "r");
44
45// unexpected values to be passed to $haystack 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*/ "hello, world",
77       'hello, 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($input, $needle, $encoding));
98  $iterator++;
99};
100
101echo "Done";
102?>
103--EXPECTF--
104*** Testing iconv_strrpos() : usage variations ***
105
106-- Iteration 1 --
107bool(false)
108
109-- Iteration 2 --
110bool(false)
111
112-- Iteration 3 --
113bool(false)
114
115-- Iteration 4 --
116bool(false)
117
118-- Iteration 5 --
119bool(false)
120
121-- Iteration 6 --
122bool(false)
123
124-- Iteration 7 --
125bool(false)
126
127-- Iteration 8 --
128bool(false)
129
130-- Iteration 9 --
131bool(false)
132
133-- Iteration 10 --
134bool(false)
135
136-- Iteration 11 --
137bool(false)
138
139-- Iteration 12 --
140bool(false)
141
142-- Iteration 13 --
143bool(false)
144
145-- Iteration 14 --
146bool(false)
147
148-- Iteration 15 --
149bool(false)
150
151-- Iteration 16 --
152bool(false)
153
154-- Iteration 17 --
155bool(false)
156
157-- Iteration 18 --
158int(7)
159
160-- Iteration 19 --
161int(7)
162
163-- Iteration 20 --
164int(7)
165
166-- Iteration 21 --
167int(7)
168
169-- Iteration 22 --
170bool(false)
171
172-- Iteration 23 --
173bool(false)
174
175-- Iteration 24 --
176
177Warning: iconv_strrpos() expects parameter 1 to be string, resource given in %s on line %d
178bool(false)
179Done
180