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