1--TEST-- 2Test str_shuffle() function : usage variations - test values for $haystack argument 3--FILE-- 4<?php 5 6/* Prototype : string str_shuffle ( string $str ) 7 * Description: Randomly shuffles a string 8 * Source code: ext/standard/string.c 9*/ 10 11echo "*** Testing str_shuffle() function: with unexpected inputs for 'string' argument ***\n"; 12 13//get an unset variable 14$unset_var = 'string_val'; 15unset($unset_var); 16 17//defining a class 18class sample { 19 public function __toString() { 20 return "sample object"; 21 } 22} 23 24//getting the resource 25$file_handle = fopen(__FILE__, "r"); 26 27// array with different values for $input 28$inputs = array ( 29 30 // integer values 31/*1*/ 0, 32 1, 33 -2, 34 2147483647, 35 -2147483648, 36 37 // float values 38/*6*/ 10.5, 39 -20.5, 40 10.1234567e10, 41 42 // array values 43/*9*/ array(), 44 array(0), 45 array(1, 2), 46 47 // boolean values 48/*12*/ true, 49 false, 50 TRUE, 51 FALSE, 52 53 // null vlaues 54/*16*/ NULL, 55 null, 56 57 // objects 58/*18*/ new sample(), 59 60 // resource 61/*19*/ $file_handle, 62 63 // undefined variable 64/*20*/ @$undefined_var, 65 66 // unset variable 67/*21*/ @$unset_var 68); 69 70 71// loop through with each element of the $inputs array to test str_shuffle() function 72$count = 1; 73foreach($inputs as $input) { 74 echo "-- Iteration $count --\n"; 75 var_dump( str_shuffle($input) ); 76 $count ++; 77} 78 79fclose($file_handle); //closing the file handle 80 81?> 82===DONE=== 83--EXPECTF-- 84*** Testing str_shuffle() function: with unexpected inputs for 'string' argument *** 85-- Iteration 1 -- 86string(1) "0" 87-- Iteration 2 -- 88string(1) "1" 89-- Iteration 3 -- 90string(2) "%s" 91-- Iteration 4 -- 92string(10) "%s" 93-- Iteration 5 -- 94string(11) "%s" 95-- Iteration 6 -- 96string(4) "%s" 97-- Iteration 7 -- 98string(5) "%s" 99-- Iteration 8 -- 100string(12) "%s" 101-- Iteration 9 -- 102 103Warning: str_shuffle() expects parameter 1 to be string, array given in %s on line %d 104NULL 105-- Iteration 10 -- 106 107Warning: str_shuffle() expects parameter 1 to be string, array given in %s on line %d 108NULL 109-- Iteration 11 -- 110 111Warning: str_shuffle() expects parameter 1 to be string, array given in %s on line %d 112NULL 113-- Iteration 12 -- 114string(1) "1" 115-- Iteration 13 -- 116string(0) "" 117-- Iteration 14 -- 118string(1) "1" 119-- Iteration 15 -- 120string(0) "" 121-- Iteration 16 -- 122string(0) "" 123-- Iteration 17 -- 124string(0) "" 125-- Iteration 18 -- 126string(13) "%s" 127-- Iteration 19 -- 128 129Warning: str_shuffle() expects parameter 1 to be string, resource given in %s on line %d 130NULL 131-- Iteration 20 -- 132string(0) "" 133-- Iteration 21 -- 134string(0) "" 135===DONE=== 136