1--TEST--
2SPL: Test class_implements() function : variation
3--FILE--
4<?php
5/* Prototype  : array class_implements(mixed what [, bool autoload ])
6 * Description: Return all classes and interfaces implemented by SPL
7 * Source code: ext/spl/php_spl.c
8 * Alias to functions:
9 */
10
11echo "*** Testing class_implements() : variation ***\n";
12
13
14// Define error handler
15function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
16	if (error_reporting() != 0) {
17		// report non-silenced errors
18		echo "Error: $err_no - $err_msg, $filename($linenum)\n";
19	}
20}
21set_error_handler('test_error_handler');
22
23// Initialise function arguments not being substituted (if any)
24$autoload = true;
25
26//resource
27$res = fopen(__FILE__,'r');
28
29//get an unset variable
30$unset_var = 10;
31unset ($unset_var);
32
33// define some classes
34class classWithToString
35{
36	public function __toString() {
37		return "Class A object";
38	}
39}
40
41class classWithoutToString
42{
43}
44
45// heredoc string
46$heredoc = <<<EOT
47hello world
48EOT;
49
50// add arrays
51$index_array = array (1, 2, 3);
52$assoc_array = array ('one' => 1, 'two' => 2);
53
54//array of values to iterate over
55$inputs = array(
56
57      // int data
58      'int 0' => 0,
59      'int 1' => 1,
60      'int 12345' => 12345,
61      'int -12345' => -2345,
62
63      // float data
64      'float 10.5' => 10.5,
65      'float -10.5' => -10.5,
66      'float 12.3456789000e10' => 12.3456789000e10,
67      'float -12.3456789000e10' => -12.3456789000e10,
68      'float .5' => .5,
69
70      // array data
71      'empty array' => array(),
72      'int indexed array' => $index_array,
73      'associative array' => $assoc_array,
74      'nested arrays' => array('foo', $index_array, $assoc_array),
75
76      // null data
77      'uppercase NULL' => NULL,
78      'lowercase null' => null,
79
80      // boolean data
81      'lowercase true' => true,
82      'lowercase false' =>false,
83      'uppercase TRUE' =>TRUE,
84      'uppercase FALSE' =>FALSE,
85
86      // empty data
87      'empty string DQ' => "",
88      'empty string SQ' => '',
89
90      // object data
91      'instance of classWithToString' => new classWithToString(),
92      'instance of classWithoutToString' => new classWithoutToString(),
93
94      // undefined data
95      'undefined var' => @$undefined_var,
96
97      // unset data
98      'unset var' => @$unset_var,
99
100      //resource
101      'resource' => $res,
102);
103
104// loop through each element of the array for pattern
105
106foreach($inputs as $key =>$value) {
107      echo "\n--$key--\n";
108      var_dump( class_implements($value, $autoload) );
109};
110
111fclose($res);
112
113?>
114===DONE===
115--EXPECTF--
116*** Testing class_implements() : variation ***
117
118--int 0--
119Error: 2 - class_implements(): object or string expected, %s(%d)
120bool(false)
121
122--int 1--
123Error: 2 - class_implements(): object or string expected, %s(%d)
124bool(false)
125
126--int 12345--
127Error: 2 - class_implements(): object or string expected, %s(%d)
128bool(false)
129
130--int -12345--
131Error: 2 - class_implements(): object or string expected, %s(%d)
132bool(false)
133
134--float 10.5--
135Error: 2 - class_implements(): object or string expected, %s(%d)
136bool(false)
137
138--float -10.5--
139Error: 2 - class_implements(): object or string expected, %s(%d)
140bool(false)
141
142--float 12.3456789000e10--
143Error: 2 - class_implements(): object or string expected, %s(%d)
144bool(false)
145
146--float -12.3456789000e10--
147Error: 2 - class_implements(): object or string expected, %s(%d)
148bool(false)
149
150--float .5--
151Error: 2 - class_implements(): object or string expected, %s(%d)
152bool(false)
153
154--empty array--
155Error: 2 - class_implements(): object or string expected, %s(%d)
156bool(false)
157
158--int indexed array--
159Error: 2 - class_implements(): object or string expected, %s(%d)
160bool(false)
161
162--associative array--
163Error: 2 - class_implements(): object or string expected, %s(%d)
164bool(false)
165
166--nested arrays--
167Error: 2 - class_implements(): object or string expected, %s(%d)
168bool(false)
169
170--uppercase NULL--
171Error: 2 - class_implements(): object or string expected, %s(%d)
172bool(false)
173
174--lowercase null--
175Error: 2 - class_implements(): object or string expected, %s(%d)
176bool(false)
177
178--lowercase true--
179Error: 2 - class_implements(): object or string expected, %s(%d)
180bool(false)
181
182--lowercase false--
183Error: 2 - class_implements(): object or string expected, %s(%d)
184bool(false)
185
186--uppercase TRUE--
187Error: 2 - class_implements(): object or string expected, %s(%d)
188bool(false)
189
190--uppercase FALSE--
191Error: 2 - class_implements(): object or string expected, %s(%d)
192bool(false)
193
194--empty string DQ--
195Error: 2 - class_implements(): Class  does not exist and could not be loaded, %s(%d)
196bool(false)
197
198--empty string SQ--
199Error: 2 - class_implements(): Class  does not exist and could not be loaded, %s(%d)
200bool(false)
201
202--instance of classWithToString--
203array(0) {
204}
205
206--instance of classWithoutToString--
207array(0) {
208}
209
210--undefined var--
211Error: 2 - class_implements(): object or string expected, %s(%d)
212bool(false)
213
214--unset var--
215Error: 2 - class_implements(): object or string expected, %s(%d)
216bool(false)
217
218--resource--
219Error: 2 - class_implements(): object or string expected, %s(%d)
220bool(false)
221===DONE===
222