1--TEST--
2Test chop() function : usage variations  - unexpected values for charlist argument
3--FILE--
4<?php
5/* Prototype  : string chop ( string $str [, string $charlist] )
6 * Description: Strip whitespace (or other characters) from the end of a string
7 * Source code: ext/standard/string.c
8*/
9
10/*
11 * Testing chop() : with different unexpected values for charlist argument passes to the function
12*/
13
14echo "*** Testing chop() : with different unexpected values for charlist argument ***\n";
15// initialize all required variables
16$str = 'hello world12345 ';
17
18// get an unset variable
19$unset_var = 'string_val';
20unset($unset_var);
21
22// declaring class
23class sample  {
24  public function __toString()  {
25  return "@# $%12345";
26  }
27}
28
29// defining a resource
30$file_handle = fopen(__FILE__, 'r');
31
32// array with different values
33$values =  array (
34
35  // integer values
36  0,
37  1,
38  12345,
39  -2345,
40
41  // float values
42  10.5,
43  -10.5,
44  10.1234567e10,
45  10.7654321E-10,
46  .5,
47
48  // array values
49  array(),
50  array(0),
51  array(1),
52  array(1, 2),
53  array('color' => 'red', 'item' => 'pen'),
54
55  // boolean values
56  true,
57  false,
58  TRUE,
59  FALSE,
60
61  // objects
62  new sample(),
63
64  // empty string
65  "",
66  '',
67
68  // null values
69  NULL,
70  null,
71
72  // resource
73  $file_handle,
74
75  // undefined variable
76  $undefined_var,
77
78  // unset variable
79  $unset_var
80
81);
82
83
84// loop through each element of the array and check the working of chop()
85// when $charlist argument is supplied with different values
86
87echo "\n--- Testing chop() by supplying different values for 'charlist' argument ---\n";
88$counter = 1;
89for($index = 0; $index < count($values); $index ++) {
90  echo "-- Iteration $counter --\n";
91  $charlist = $values [$index];
92
93  var_dump( chop($str, $charlist) );
94
95  $counter ++;
96}
97
98// closing the resource
99fclose($file_handle);
100
101echo "Done\n";
102?>
103--EXPECTF--
104*** Testing chop() : with different unexpected values for charlist argument ***
105
106Notice: Undefined variable: undefined_var in %s on line %d
107
108Notice: Undefined variable: unset_var in %s on line %d
109
110--- Testing chop() by supplying different values for 'charlist' argument ---
111-- Iteration 1 --
112string(17) "hello world12345 "
113-- Iteration 2 --
114string(17) "hello world12345 "
115-- Iteration 3 --
116string(17) "hello world12345 "
117-- Iteration 4 --
118string(17) "hello world12345 "
119-- Iteration 5 --
120string(17) "hello world12345 "
121-- Iteration 6 --
122string(17) "hello world12345 "
123-- Iteration 7 --
124string(17) "hello world12345 "
125-- Iteration 8 --
126string(17) "hello world12345 "
127-- Iteration 9 --
128string(17) "hello world12345 "
129-- Iteration 10 --
130
131Warning: chop() expects parameter 2 to be string, array given in %s on line %d
132NULL
133-- Iteration 11 --
134
135Warning: chop() expects parameter 2 to be string, array given in %s on line %d
136NULL
137-- Iteration 12 --
138
139Warning: chop() expects parameter 2 to be string, array given in %s on line %d
140NULL
141-- Iteration 13 --
142
143Warning: chop() expects parameter 2 to be string, array given in %s on line %d
144NULL
145-- Iteration 14 --
146
147Warning: chop() expects parameter 2 to be string, array given in %s on line %d
148NULL
149-- Iteration 15 --
150string(17) "hello world12345 "
151-- Iteration 16 --
152string(17) "hello world12345 "
153-- Iteration 17 --
154string(17) "hello world12345 "
155-- Iteration 18 --
156string(17) "hello world12345 "
157-- Iteration 19 --
158string(11) "hello world"
159-- Iteration 20 --
160string(17) "hello world12345 "
161-- Iteration 21 --
162string(17) "hello world12345 "
163-- Iteration 22 --
164string(17) "hello world12345 "
165-- Iteration 23 --
166string(17) "hello world12345 "
167-- Iteration 24 --
168
169Warning: chop() expects parameter 2 to be string, resource given in %s on line %d
170NULL
171-- Iteration 25 --
172string(17) "hello world12345 "
173-- Iteration 26 --
174string(17) "hello world12345 "
175Done
176