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