1--TEST--
2Test strlen() function : usage variations - unexpected input for '$string' argument
3--FILE--
4<?php
5
6/* Prototype  : int strlen  ( string $string  )
7 * Description: Get string length
8 * Source code: ext/standard/string.c
9*/
10
11echo "*** Testing strlen() : with unexpected input for 'string' argument ***\n";
12
13//get an unset variable
14$unset_var = 'string_val';
15unset($unset_var);
16
17//defining a class
18class sample  {
19  public function __toString() {
20    return "sample object";
21  }
22}
23
24//getting the resource
25$file_handle = fopen(__FILE__, "r");
26
27// array with different values for $input
28$inputs =  array (
29
30		  // integer values
31/*1*/	  0,
32		  1,
33		  -2,
34		  2147483647,
35		  -2147483648,
36
37		  // float values
38/*6*/	  10.5,
39		  -20.5,
40		  10.1234567e10,
41
42		  // array values
43/*9*/	  array(),
44		  array(0),
45		  array(1, 2),
46
47		  // boolean values
48/*12*/	  true,
49		  false,
50		  TRUE,
51		  FALSE,
52
53		  // null values
54/*16*/	  NULL,
55		  null,
56
57		  // objects
58/*18*/	  new sample(),
59
60		  // resource
61/*19*/	  $file_handle,
62
63		  // undefined variable
64/*20*/	  @$undefined_var,
65
66		  // unset variable
67/*21*/	  @$unset_var
68);
69
70//defining '$pad_length' argument
71$pad_length = "20";
72
73// loop through with each element of the $inputs array to test strlen() function
74$count = 1;
75foreach($inputs as $input) {
76  echo "-- Iteration $count --\n";
77  var_dump( strlen($input) );
78  $count ++;
79}
80
81fclose($file_handle);  //closing the file handle
82
83?>
84===DONE===
85--EXPECTF--
86*** Testing strlen() : with unexpected input for 'string' argument ***
87-- Iteration 1 --
88int(1)
89-- Iteration 2 --
90int(1)
91-- Iteration 3 --
92int(2)
93-- Iteration 4 --
94int(10)
95-- Iteration 5 --
96int(11)
97-- Iteration 6 --
98int(4)
99-- Iteration 7 --
100int(5)
101-- Iteration 8 --
102int(12)
103-- Iteration 9 --
104
105Warning: strlen() expects parameter 1 to be string, array given in %s on line %d
106NULL
107-- Iteration 10 --
108
109Warning: strlen() expects parameter 1 to be string, array given in %s on line %d
110NULL
111-- Iteration 11 --
112
113Warning: strlen() expects parameter 1 to be string, array given in %s on line %d
114NULL
115-- Iteration 12 --
116int(1)
117-- Iteration 13 --
118int(0)
119-- Iteration 14 --
120int(1)
121-- Iteration 15 --
122int(0)
123-- Iteration 16 --
124int(0)
125-- Iteration 17 --
126int(0)
127-- Iteration 18 --
128int(13)
129-- Iteration 19 --
130
131Warning: strlen() expects parameter 1 to be string, resource given in %s on line %d
132NULL
133-- Iteration 20 --
134int(0)
135-- Iteration 21 --
136int(0)
137===DONE===
138