1--TEST-- 2Test sha1() function : usage variations - unexpected values for 'str' 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 'str' ***\n"; 11 12$raw = false; 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 // boolean data 58/*17*/ true, 59 false, 60 TRUE, 61 FALSE, 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 'str' argument 81for($count = 0; $count < count($values); $count++) { 82 echo "-- Iteration ".($count+1)." --\n"; 83 var_dump( sha1($values[$count], $raw) ); 84} 85 86//closing resource 87fclose($fp); 88 89?> 90===DONE=== 91--EXPECTF-- 92*** Testing sha1() : unexpected values for 'str' *** 93-- Iteration 1 -- 94string(40) "b6589fc6ab0dc82cf12099d1c2d40ab994e8410c" 95-- Iteration 2 -- 96string(40) "356a192b7913b04c54574d18c28d46e6395428ab" 97-- Iteration 3 -- 98string(40) "8cb2237d0679ca88db6464eac60da96345513964" 99-- Iteration 4 -- 100string(40) "bc97c643aba3b6c6abe253222f439d4002a87528" 101-- Iteration 5 -- 102string(40) "1287384bc5ef3ab84a36a5ef1d888df2763567f4" 103-- Iteration 6 -- 104string(40) "c9d6e1b691f17c8ae6d458984a5f56f80e62a60b" 105-- Iteration 7 -- 106string(40) "39493e1e645578a655f532e1f9bcff67991f2c2f" 107-- Iteration 8 -- 108string(40) "681b45cae882ad795afd54ccc2a04ad58e056b83" 109-- Iteration 9 -- 110string(40) "1b390cd54a0c0d4f27fa7adf23e3c45536e9f37c" 111-- Iteration 10 -- 112 113Warning: sha1() expects parameter 1 to be string, array given in %s on line %d 114NULL 115-- Iteration 11 -- 116 117Warning: sha1() expects parameter 1 to be string, array given in %s on line %d 118NULL 119-- Iteration 12 -- 120 121Warning: sha1() expects parameter 1 to be string, array given in %s on line %d 122NULL 123-- Iteration 13 -- 124 125Warning: sha1() expects parameter 1 to be string, array given in %s on line %d 126NULL 127-- Iteration 14 -- 128 129Warning: sha1() expects parameter 1 to be string, array given in %s on line %d 130NULL 131-- Iteration 15 -- 132string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709" 133-- Iteration 16 -- 134string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709" 135-- Iteration 17 -- 136string(40) "356a192b7913b04c54574d18c28d46e6395428ab" 137-- Iteration 18 -- 138string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709" 139-- Iteration 19 -- 140string(40) "356a192b7913b04c54574d18c28d46e6395428ab" 141-- Iteration 20 -- 142string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709" 143-- Iteration 21 -- 144string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709" 145-- Iteration 22 -- 146string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709" 147-- Iteration 23 -- 148string(40) "1615307cc4523f183e777df67f168c86908e8007" 149-- Iteration 24 -- 150string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709" 151-- Iteration 25 -- 152string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709" 153-- Iteration 26 -- 154 155Warning: sha1() expects parameter 1 to be string, resource given in %s on line %d 156NULL 157===DONE=== 158