1--TEST-- 2Test sha1() function : usage variations - unexpected values for 'raw' argument 3--FILE-- 4<?php 5 6/* Prototype: string sha1 ( string $str [, bool $raw_output ] ) 7 * Description: Calculate the sha1 hash of a string 8 */ 9 10echo "*** Testing sha1() : unexpected values for 'raw' ***\n"; 11 12$string = "Hello World"; 13 14//get an unset variable 15$unset_var = 10; 16unset ($unset_var); 17 18//defining class for object variable 19class MyClass 20{ 21 public function __toString() 22 { 23 return "object"; 24 } 25} 26 27//resource variable 28$fp = fopen(__FILE__, 'r'); 29 30//different values for 'str' argument 31$values = array( 32 33 // int data 34/*1*/ 0, 35 1, 36 12345, 37 -2345, 38 39 // float data 40/*5*/ 10.5, 41 -10.5, 42 10.1234567e10, 43 10.1234567E-10, 44 .5, 45 46 // array data 47/*10*/ array(), 48 array(0), 49 array(1), 50 array(1, 2), 51 array('color' => 'red', 'item' => 'pen'), 52 53 // null data 54/*15*/ NULL, 55 null, 56 57 // string data 58/*17*/ "ABC", 59 'abc', 60 "0abc", 61 "123abc", 62 63 // empty data 64/*21*/ "", 65 '', 66 67 // object data 68/*23*/ new MyClass(), 69 70 // undefined data 71/*24*/ @$undefined_var, 72 73 // unset data 74/*25*/ @$unset_var, 75 76 //resource data 77/*26*/ $fp 78); 79 80// loop through each element of $values for 'raw' argument 81for($count = 0; $count < count($values); $count++) { 82 echo "-- Iteration ".($count+1)." --\n"; 83 // use bin2hex to catch those cases were raw is true 84 var_dump( bin2hex(sha1($string, $values[$count])) ); 85} 86 87//closing resource 88fclose($fp); 89 90?> 91===DONE=== 92--EXPECTF-- 93*** Testing sha1() : unexpected values for 'raw' *** 94-- Iteration 1 -- 95string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430" 96-- Iteration 2 -- 97string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0" 98-- Iteration 3 -- 99string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0" 100-- Iteration 4 -- 101string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0" 102-- Iteration 5 -- 103string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0" 104-- Iteration 6 -- 105string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0" 106-- Iteration 7 -- 107string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0" 108-- Iteration 8 -- 109string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0" 110-- Iteration 9 -- 111string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0" 112-- Iteration 10 -- 113 114Warning: sha1() expects parameter 2 to be bool, array given in %s on line %d 115string(0) "" 116-- Iteration 11 -- 117 118Warning: sha1() expects parameter 2 to be bool, array given in %s on line %d 119string(0) "" 120-- Iteration 12 -- 121 122Warning: sha1() expects parameter 2 to be bool, array given in %s on line %d 123string(0) "" 124-- Iteration 13 -- 125 126Warning: sha1() expects parameter 2 to be bool, array given in %s on line %d 127string(0) "" 128-- Iteration 14 -- 129 130Warning: sha1() expects parameter 2 to be bool, array given in %s on line %d 131string(0) "" 132-- Iteration 15 -- 133string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430" 134-- Iteration 16 -- 135string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430" 136-- Iteration 17 -- 137string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0" 138-- Iteration 18 -- 139string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0" 140-- Iteration 19 -- 141string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0" 142-- Iteration 20 -- 143string(40) "0a4d55a8d778e5022fab701977c5d840bbc486d0" 144-- Iteration 21 -- 145string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430" 146-- Iteration 22 -- 147string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430" 148-- Iteration 23 -- 149 150Warning: sha1() expects parameter 2 to be bool, object given in %s on line %d 151string(0) "" 152-- Iteration 24 -- 153string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430" 154-- Iteration 25 -- 155string(80) "30613464353561386437373865353032326661623730313937376335643834306262633438366430" 156-- Iteration 26 -- 157 158Warning: sha1() expects parameter 2 to be bool, resource given in %s on line %d 159string(0) "" 160===DONE=== 161