1--TEST-- 2Test rtrim() function : usage variations - test values for $charlist argument 3--FILE-- 4<?php 5 6/* Prototype : string rtrim ( string $str [, string $charlist ] ) 7 * Description: Strip whitespace (or other characters) from the end of a string. 8 * Source code: ext/standard/string.c 9*/ 10 11echo "*** Testing rtrim() function: with unexpected inputs for 'charlist' 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 2147483647, 36 -2147483648, 37 38 // float values 39/*7*/ 10.5, 40 -20.5, 41 10.1234567e10, 42 43 // array values 44/*10*/ array(), 45 array(0), 46 array(1, 2), 47 48 // boolean values 49/*13*/ true, 50 false, 51 TRUE, 52 FALSE, 53 54 // null values 55/*17*/ NULL, 56 null, 57 58 // objects 59/*19*/ new sample(), 60 61 // resource 62/*20*/ $file_handle, 63 64 // undefined variable 65/*21*/ @$undefined_var, 66 67 // unset variable 68/*22*/ @$unset_var 69); 70 71// loop through with each element of the $inputs array to test rtrim() function 72$count = 1; 73foreach($inputs as $charlist) { 74 echo "-- Iteration $count --\n"; 75 // strip white space and any "minus" signs 76 var_dump( rtrim("!---Hello World---!", $charlist) ); 77 $count ++; 78} 79 80fclose($file_handle); //closing the file handle 81 82?> 83===DONE=== 84--EXPECTF-- 85*** Testing rtrim() function: with unexpected inputs for 'charlist' argument *** 86-- Iteration 1 -- 87string(19) "!---Hello World---!" 88-- Iteration 2 -- 89string(19) "!---Hello World---!" 90-- Iteration 3 -- 91string(19) "!---Hello World---!" 92-- Iteration 4 -- 93string(19) "!---Hello World---!" 94-- Iteration 5 -- 95string(19) "!---Hello World---!" 96-- Iteration 6 -- 97string(19) "!---Hello World---!" 98-- Iteration 7 -- 99string(19) "!---Hello World---!" 100-- Iteration 8 -- 101string(19) "!---Hello World---!" 102-- Iteration 9 -- 103string(19) "!---Hello World---!" 104-- Iteration 10 -- 105 106Warning: rtrim() expects parameter 2 to be string, array given in %s on line %d 107NULL 108-- Iteration 11 -- 109 110Warning: rtrim() expects parameter 2 to be string, array given in %s on line %d 111NULL 112-- Iteration 12 -- 113 114Warning: rtrim() expects parameter 2 to be string, array given in %s on line %d 115NULL 116-- Iteration 13 -- 117string(19) "!---Hello World---!" 118-- Iteration 14 -- 119string(19) "!---Hello World---!" 120-- Iteration 15 -- 121string(19) "!---Hello World---!" 122-- Iteration 16 -- 123string(19) "!---Hello World---!" 124-- Iteration 17 -- 125string(19) "!---Hello World---!" 126-- Iteration 18 -- 127string(19) "!---Hello World---!" 128-- Iteration 19 -- 129string(19) "!---Hello World---!" 130-- Iteration 20 -- 131 132Warning: rtrim() expects parameter 2 to be string, resource given in %s on line %d 133NULL 134-- Iteration 21 -- 135string(19) "!---Hello World---!" 136-- Iteration 22 -- 137string(19) "!---Hello World---!" 138===DONE=== 139