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