1--TEST--
2Test crc32() function : usage variations - unexpected values
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4)
6  die("skip this test is for 32bit platform only");
7?>
8
9--FILE--
10<?php
11/* Prototype  : string crc32(string $str)
12 * Description: Calculate the crc32 polynomial of a string
13 * Source code: ext/standard/crc32.c
14 * Alias to functions: none
15*/
16
17/*
18 * Testing crc32() : with unexpected values for str argument
19*/
20
21echo "*** Testing crc32() : with unexpected values for str argument ***\n";
22
23//get an unset variable
24$unset_var = 10;
25unset ($unset_var);
26
27// declaring class
28class sample  {
29  public function __toString() {
30    return "object";
31  }
32}
33
34// creating a file resource
35$file_handle = fopen(__FILE__, 'r');
36
37//array of values to iterate over
38$values = array(
39
40      // int data
41      0,
42      1,
43      12345,
44      -2345,
45
46      // float data
47      10.5,
48      -10.5,
49      10.1234567e10,
50      10.7654321E-10,
51      .5,
52
53      // array data
54      array(),
55      array(0),
56      array(1),
57      array(1, 2),
58      array('color' => 'red', 'item' => 'pen'),
59
60      // null data
61      NULL,
62      null,
63
64      // boolean data
65      true,
66      false,
67      TRUE,
68      FALSE,
69
70      // empty data
71      "",
72      '',
73
74      // object data
75      new sample(),
76
77      // undefined data
78      $undefined_var,
79
80      // unset data
81      $unset_var,
82
83      // resource
84      $file_handle
85);
86
87// loop through each element of the array for str
88
89$count = 1;
90foreach($values as $value) {
91      echo "\n-- Iteration $count --\n";
92      var_dump( crc32($value) );
93      $count++;
94};
95
96// closing the resource
97fclose($file_handle);
98
99echo "Done";
100?>
101--EXPECTF--
102*** Testing crc32() : with unexpected values for str argument ***
103
104Notice: Undefined variable: undefined_var in %s on line %d
105
106Notice: Undefined variable: unset_var in %s on line %d
107
108-- Iteration 1 --
109int(-186917087)
110
111-- Iteration 2 --
112int(-2082672713)
113
114-- Iteration 3 --
115int(-873121252)
116
117-- Iteration 4 --
118int(1860518047)
119
120-- Iteration 5 --
121int(269248583)
122
123-- Iteration 6 --
124int(-834950157)
125
126-- Iteration 7 --
127int(-965354630)
128
129-- Iteration 8 --
130int(1376932222)
131
132-- Iteration 9 --
133int(-2036403827)
134
135-- Iteration 10 --
136
137Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
138NULL
139
140-- Iteration 11 --
141
142Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
143NULL
144
145-- Iteration 12 --
146
147Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
148NULL
149
150-- Iteration 13 --
151
152Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
153NULL
154
155-- Iteration 14 --
156
157Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
158NULL
159
160-- Iteration 15 --
161int(0)
162
163-- Iteration 16 --
164int(0)
165
166-- Iteration 17 --
167int(-2082672713)
168
169-- Iteration 18 --
170int(0)
171
172-- Iteration 19 --
173int(-2082672713)
174
175-- Iteration 20 --
176int(0)
177
178-- Iteration 21 --
179int(0)
180
181-- Iteration 22 --
182int(0)
183
184-- Iteration 23 --
185int(-1465013268)
186
187-- Iteration 24 --
188int(0)
189
190-- Iteration 25 --
191int(0)
192
193-- Iteration 26 --
194
195Warning: crc32() expects parameter 1 to be string, resource given in %s on line %d
196NULL
197Done