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 // boolean values 42/*11*/ true, 43 false, 44 TRUE, 45 FALSE, 46 47 // null values 48/*15*/ NULL, 49 null, 50 51 // undefined variable 52/*19*/ @$undefined_var, 53 54 // unset variable 55/*20*/ @$unset_var 56); 57 58// loop through with each element of the $inputs array to test chr() function 59$count = 1; 60foreach($inputs as $input) { 61 echo "-- Iteration $count --\n"; 62 var_dump( bin2hex(chr($input)) ); 63 $count ++; 64} 65 66fclose($file_handle); //closing the file handle 67 68?> 69===DONE=== 70--EXPECT-- 71*** Testing chr() function: with unexpected inputs for 'ascii' argument *** 72-- Iteration 1 -- 73string(2) "00" 74-- Iteration 2 -- 75string(2) "01" 76-- Iteration 3 -- 77string(2) "ff" 78-- Iteration 4 -- 79string(2) "00" 80-- Iteration 5 -- 81string(2) "0a" 82-- Iteration 6 -- 83string(2) "ec" 84-- Iteration 7 -- 85string(2) "48" 86-- Iteration 8 -- 87string(2) "01" 88-- Iteration 9 -- 89string(2) "00" 90-- Iteration 10 -- 91string(2) "01" 92-- Iteration 11 -- 93string(2) "00" 94-- Iteration 12 -- 95string(2) "00" 96-- Iteration 13 -- 97string(2) "00" 98-- Iteration 14 -- 99string(2) "00" 100-- Iteration 15 -- 101string(2) "00" 102===DONE=== 103