1--TEST--
2Test iconv_strlen() function : usage variations - Pass different data types as $encoding arg
3--SKIPIF--
4<?php
5extension_loaded('iconv') or die('skip');
6function_exists('iconv_strlen') or die("skip iconv_strlen() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : int iconv_strlen(string str [, string charset])
11 * Description: Get character numbers of a string
12 * Source code: ext/iconv/iconv.c
13 */
14
15/*
16 * Test iconv_strlen() by passing different data types as $encoding argument.
17 * Where possible 'UTF-8' has been entered as a string value
18 */
19
20echo "*** Testing iconv_strlen() : usage variations ***\n";
21
22// Initialise function arguments not being substituted
23$str = 'string value';
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 "UTF-8";
34  }
35}
36
37// heredoc string
38$heredoc = <<<EOT
39UTF-8
40EOT;
41
42// get a resource variable
43$fp = fopen(__FILE__, "r");
44
45// unexpected values to be passed to $input 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*/ "UTF-8",
77       'UTF-8',
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_strlen()
94$iterator = 1;
95foreach($inputs as $input) {
96  echo "\n-- Iteration $iterator --\n";
97  var_dump( iconv_strlen($str, $input));
98  $iterator++;
99};
100
101fclose($fp);
102
103echo "Done";
104?>
105--EXPECTF--
106*** Testing iconv_strlen() : usage variations ***
107
108-- Iteration 1 --
109
110Notice: iconv_strlen(): Wrong charset, conversion from `0' to `UCS-4LE' is not allowed in %s on line %d
111bool(false)
112
113-- Iteration 2 --
114
115Notice: iconv_strlen(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d
116bool(false)
117
118-- Iteration 3 --
119
120Notice: iconv_strlen(): Wrong charset, conversion from `12345' to `UCS-4LE' is not allowed in %s on line %d
121bool(false)
122
123-- Iteration 4 --
124
125Notice: iconv_strlen(): Wrong charset, conversion from `-2345' to `UCS-4LE' is not allowed in %s on line %d
126bool(false)
127
128-- Iteration 5 --
129
130Notice: iconv_strlen(): Wrong charset, conversion from `10.5' to `UCS-4LE' is not allowed in %s on line %d
131bool(false)
132
133-- Iteration 6 --
134
135Notice: iconv_strlen(): Wrong charset, conversion from `-10.5' to `UCS-4LE' is not allowed in %s on line %d
136bool(false)
137
138-- Iteration 7 --
139
140Notice: iconv_strlen(): Wrong charset, conversion from `123456789000' to `UCS-4LE' is not allowed in %s on line %d
141bool(false)
142
143-- Iteration 8 --
144
145Notice: iconv_strlen(): Wrong charset, conversion from `1.23456789E-9' to `UCS-4LE' is not allowed in %s on line %d
146bool(false)
147
148-- Iteration 9 --
149
150Notice: iconv_strlen(): Wrong charset, conversion from `0.5' to `UCS-4LE' is not allowed in %s on line %d
151bool(false)
152
153-- Iteration 10 --
154int(12)
155
156-- Iteration 11 --
157int(12)
158
159-- Iteration 12 --
160
161Notice: iconv_strlen(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d
162bool(false)
163
164-- Iteration 13 --
165int(12)
166
167-- Iteration 14 --
168
169Notice: iconv_strlen(): Wrong charset, conversion from `1' to `UCS-4LE' is not allowed in %s on line %d
170bool(false)
171
172-- Iteration 15 --
173int(12)
174
175-- Iteration 16 --
176int(12)
177
178-- Iteration 17 --
179int(12)
180
181-- Iteration 18 --
182int(12)
183
184-- Iteration 19 --
185int(12)
186
187-- Iteration 20 --
188int(12)
189
190-- Iteration 21 --
191int(12)
192
193-- Iteration 22 --
194int(12)
195
196-- Iteration 23 --
197int(12)
198
199-- Iteration 24 --
200
201Warning: iconv_strlen() expects parameter 2 to be string, resource given in %s on line %d
202bool(false)
203Done
204