1--TEST-- 2Test chr() function : usage variations - test values for $ascii argument 3--FILE-- 4<?php 5 6/* Prototype : string chr ( int $ascii ) 7 * Description: Return a specific character 8 * Source code: ext/standard/string.c 9*/ 10 11echo "*** Testing chr() function: with unexpected inputs for 'ascii' 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 255, 34 256, 35 36 // float values 37/*5*/ 10.5, 38 -20.5, 39 1.1234e6, 40 41 // array values 42/*8*/ array(), 43 array(0), 44 array(1, 2), 45 46 // boolean values 47/*11*/ true, 48 false, 49 TRUE, 50 FALSE, 51 52 // null values 53/*15*/ NULL, 54 null, 55 56 // objects 57/*17*/ new sample(), 58 59 // resource 60/*18*/ $file_handle, 61 62 // undefined variable 63/*19*/ @$undefined_var, 64 65 // unset variable 66/*20*/ @$unset_var 67); 68 69// loop through with each element of the $inputs array to test chr() function 70$count = 1; 71foreach($inputs as $input) { 72 echo "-- Iteration $count --\n"; 73 var_dump( bin2hex(chr($input)) ); 74 $count ++; 75} 76 77fclose($file_handle); //closing the file handle 78 79?> 80===DONE=== 81--EXPECT-- 82*** Testing chr() function: with unexpected inputs for 'ascii' argument *** 83-- Iteration 1 -- 84string(2) "00" 85-- Iteration 2 -- 86string(2) "01" 87-- Iteration 3 -- 88string(2) "ff" 89-- Iteration 4 -- 90string(2) "00" 91-- Iteration 5 -- 92string(2) "0a" 93-- Iteration 6 -- 94string(2) "ec" 95-- Iteration 7 -- 96string(2) "48" 97-- Iteration 8 -- 98string(2) "00" 99-- Iteration 9 -- 100string(2) "00" 101-- Iteration 10 -- 102string(2) "00" 103-- Iteration 11 -- 104string(2) "01" 105-- Iteration 12 -- 106string(2) "00" 107-- Iteration 13 -- 108string(2) "01" 109-- Iteration 14 -- 110string(2) "00" 111-- Iteration 15 -- 112string(2) "00" 113-- Iteration 16 -- 114string(2) "00" 115-- Iteration 17 -- 116string(2) "00" 117-- Iteration 18 -- 118string(2) "00" 119-- Iteration 19 -- 120string(2) "00" 121-- Iteration 20 -- 122string(2) "00" 123===DONE=== 124