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