1--TEST--
2Test strncasecmp() function : usage variations - unexpected values for 'str1'
3--FILE--
4<?php
5/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
6 * Description: Binary safe case-insensitive string comparison of the first n characters
7 * Source code: Zend/zend_builtin_functions.c
8*/
9
10/* Test strncasecmp() function with the unexpected inputs for 'str1' */
11
12echo "*** Testing strncasecmp() function: with unexpected values for 'str1' ***\n";
13/* get an unset variable */
14$unset_var = 'string_val';
15unset($unset_var);
16
17/* get resource handle */
18$file_handle = fopen(__FILE__, "r");
19
20/* declaring a class */
21class sample  {
22  public function __toString() {
23  return "object";
24  }
25}
26
27
28/* array with different values */
29$values =  array (
30  /* integer values */
31  0,
32  1,
33  12345,
34  -2345,
35
36  /* float values */
37  10.5,
38  -10.5,
39  10.5e10,
40  10.6E-10,
41  .5,
42
43  /* hexadecimal values */
44  0x12,
45  -0x12,
46
47  /* octal values */
48  012,
49  -012,
50  01.2,
51
52  /* array values */
53  array(),
54  array(0),
55  array(1),
56  array(1, 2),
57  array('color' => 'red', 'item' => 'pen'),
58
59  /* boolean values */
60  true,
61  false,
62  TRUE,
63  FALSE,
64
65  /* nulls */
66  NULL,
67  null,
68
69  /* empty string */
70  "",
71  '',
72
73  /* undefined variable */
74  @$undefined_var,
75
76  /* unset variable */
77  @$unset_var,
78
79  /* resource */
80  $file_handle,
81
82  /* object */
83  new sample()
84);
85
86/* loop through each element of the array and check the working of strncasecmp() */
87$counter = 1;
88for($index = 0; $index < count($values); $index ++) {
89  echo "-- Iteration $counter --\n";
90  $str1 = $values[$index];
91  $len = strlen($values[$index]) + 1;
92  var_dump( strncasecmp($str1, "string", $len) );
93  $counter ++;
94}
95
96fclose($file_handle);  //closing the file handle
97
98echo "*** Done ***\n";
99?>
100--EXPECTF--
101*** Testing strncasecmp() function: with unexpected values for 'str1' ***
102-- Iteration 1 --
103int(-%d)
104-- Iteration 2 --
105int(-%d)
106-- Iteration 3 --
107int(-%d)
108-- Iteration 4 --
109int(-%d)
110-- Iteration 5 --
111int(-%d)
112-- Iteration 6 --
113int(-%d)
114-- Iteration 7 --
115int(-%d)
116-- Iteration 8 --
117int(-%d)
118-- Iteration 9 --
119int(-%d)
120-- Iteration 10 --
121int(-%d)
122-- Iteration 11 --
123int(-%d)
124-- Iteration 12 --
125int(-%d)
126-- Iteration 13 --
127int(-%d)
128-- Iteration 14 --
129int(-%d)
130-- Iteration 15 --
131
132Warning: strlen() expects parameter 1 to be string, array given in %s on line 88
133
134Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line 89
135NULL
136-- Iteration 16 --
137
138Warning: strlen() expects parameter 1 to be string, array given in %s on line 88
139
140Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line 89
141NULL
142-- Iteration 17 --
143
144Warning: strlen() expects parameter 1 to be string, array given in %s on line 88
145
146Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line 89
147NULL
148-- Iteration 18 --
149
150Warning: strlen() expects parameter 1 to be string, array given in %s on line 88
151
152Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line 89
153NULL
154-- Iteration 19 --
155
156Warning: strlen() expects parameter 1 to be string, array given in %s on line 88
157
158Warning: strncasecmp() expects parameter 1 to be string, array given in %s on line 89
159NULL
160-- Iteration 20 --
161int(-%d)
162-- Iteration 21 --
163int(-%d)
164-- Iteration 22 --
165int(-%d)
166-- Iteration 23 --
167int(-%d)
168-- Iteration 24 --
169int(-%d)
170-- Iteration 25 --
171int(-%d)
172-- Iteration 26 --
173int(-%d)
174-- Iteration 27 --
175int(-%d)
176-- Iteration 28 --
177int(-%d)
178-- Iteration 29 --
179int(-%d)
180-- Iteration 30 --
181
182Warning: strlen() expects parameter 1 to be string, resource given in %s on line 88
183
184Warning: strncasecmp() expects parameter 1 to be string, resource given in %s on line 89
185NULL
186-- Iteration 31 --
187int(-%d)
188*** Done ***
189