1--TEST--
2Test rtrim() function : usage variations - test values for $str 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 'str' 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 $input) {
74  echo "-- Iteration $count --\n";
75  // strip white space and any "minus" signs
76  var_dump( rtrim($input, " !-") );
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 'str' argument ***
86-- Iteration 1 --
87string(1) "0"
88-- Iteration 2 --
89string(1) "1"
90-- Iteration 3 --
91string(3) "255"
92-- Iteration 4 --
93string(3) "256"
94-- Iteration 5 --
95string(10) "2147483647"
96-- Iteration 6 --
97string(11) "-2147483648"
98-- Iteration 7 --
99string(4) "10.5"
100-- Iteration 8 --
101string(5) "-20.5"
102-- Iteration 9 --
103string(12) "101234567000"
104-- Iteration 10 --
105
106Warning: rtrim() expects parameter 1 to be string, array given in %s on line %d
107NULL
108-- Iteration 11 --
109
110Warning: rtrim() expects parameter 1 to be string, array given in %s on line %d
111NULL
112-- Iteration 12 --
113
114Warning: rtrim() expects parameter 1 to be string, array given in %s on line %d
115NULL
116-- Iteration 13 --
117string(1) "1"
118-- Iteration 14 --
119string(0) ""
120-- Iteration 15 --
121string(1) "1"
122-- Iteration 16 --
123string(0) ""
124-- Iteration 17 --
125string(0) ""
126-- Iteration 18 --
127string(0) ""
128-- Iteration 19 --
129string(19) "  !---sample object"
130-- Iteration 20 --
131
132Warning: rtrim() expects parameter 1 to be string, resource given in %s on line %d
133NULL
134-- Iteration 21 --
135string(0) ""
136-- Iteration 22 --
137string(0) ""
138===DONE===
139