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