1--TEST--
2Test array_fill() function : usage variations - various object values for 'val' argument
3--FILE--
4<?php
5/*
6 * testing array_fill() by passing various  object values for 'val' argument
7 */
8
9echo "*** Testing array_fill() : usage variations ***\n";
10
11// Initialise function arguments not being substituted
12$start_key = 0;
13$num = 2;
14
15// class without a member
16class Test
17{
18}
19
20//class with public member, static member , constant and consturctor to initialize the public member
21class Test1
22{
23  const test1_constant = "test1";
24  public static $test1_static = 0;
25  public $member1;
26  var $var1 = 30;
27  var $var2;
28
29  function __construct($value1 , $value2)
30  {
31    $this->member1 = $value1;
32    $this->var2 = $value2;
33  }
34}
35
36// child class which inherits parent class test1
37class Child_test1 extends Test1
38{
39  public $member2;
40
41  function __construct($value1 , $value2 , $value3)
42  {
43    parent::__construct($value1 , $value2);
44    $this->member2 = $value3;
45  }
46}
47
48//class with private member, static member, constant and constructor to initialize the private member
49class Test2
50{
51  const test2_constant = "test2";
52  public static $test2_static = 0;
53  private $member1;
54  var $var1 = 30;
55  var $var2;
56
57  function __construct($value1 , $value2)
58  {
59    $this->member1 = $value1;
60    $this->var2 = $value2;
61  }
62}
63
64// child class which inherits parent class test2
65class Child_test2 extends Test2
66{
67  private $member1;
68
69  function __construct($value1 , $value2 , $value3)
70  {
71    parent::__construct($value1 , $value2);
72    $this->member1 = $value3;
73  }
74}
75
76// class with protected member, static member, constant and consturctor to initialize the protected member
77class Test3
78{
79  const test3_constant = "test3";
80  public static $test3_static = 0;
81  protected $member1;
82  var $var1 = 30;
83  var $var2;
84
85  function __construct($value1 , $value2)
86  {
87     $this->member1 = $value1;
88     $this->var2 = $value2;
89  }
90}
91
92// child class which inherits parent class test3
93class Child_test3 extends Test3
94{
95  protected $member1;
96
97  function __construct($value1 , $value2 , $value3)
98  {
99    parent::__construct($value1 , $value2);
100    $this->member1 = $value3;
101  }
102}
103
104// class with public, private, protected members, static, constant members and constructor to initialize all the members
105class Test4
106{
107  const test4_constant = "test4";
108  public static $test4_static = 0;
109  public $member1;
110  private $member2;
111  protected $member3;
112
113  function __construct($value1 , $value2 , $value3)
114  {
115    $this->member1 = $value1;
116    $this->member2 = $value2;
117    $this->member3 = $value3;
118  }
119}
120
121// child class which inherits parent class test4
122class Child_test4 extends Test4
123{
124  var $var1;
125
126  function __construct($value1 , $value2 , $value3 , $value4)
127  {
128    parent::__construct($value1 , $value2 , $value3);
129    $this->var1 = $value4;
130  }
131}
132
133// abstract class with public, private, protected members
134abstract class AbstractClass
135{
136  public $member1;
137  private $member2;
138  protected $member3;
139  var $var1 = 30;
140
141  abstract protected function display();
142}
143
144// implement abstract 'AbstractClass' class
145class ConcreteClass1 extends AbstractClass
146{
147  protected function display()
148  {
149    echo "class name is ConcreteClass1 \n";
150  }
151}
152
153
154// declarationn of the interface 'iTemplate'
155interface iTemplate
156{
157  public function display();
158}
159
160// implement the interface 'iTemplate'
161class Template1 implements iTemplate
162{
163  public function display()
164  {
165    echo "class name is Template1\n";
166  }
167}
168
169//array of object values for 'val' argument
170$objects = array(
171
172  /* 1  */  new Test(),
173            new Test1(100 , 101),
174            new Child_test1(100 , 101 , 102),
175            new Test2(100 , 101),
176  /* 5  */  new Child_test2(100 , 101 , 102),
177            new Test3(100 , 101),
178            new Child_test3(100 , 101 , 102),
179            new Test4( 100 , 101 , 102),
180            new Child_test4(100 , 101 , 102 , 103),
181            new ConcreteClass1(),
182  /* 11 */  new Template1()
183);
184
185// loop through each element of the array for 'val' argument
186// check the working of array_fill()
187echo "--- Testing array_fill() with different object values for 'val' argument ---\n";
188$counter = 1;
189for($index = 0; $index < count($objects); $index ++)
190{
191  echo "-- Iteration $counter --\n";
192  $val = $objects[$index];
193
194  var_dump( array_fill($start_key,$num,$val) );
195
196  $counter++;
197}
198
199echo "Done";
200?>
201--EXPECTF--
202*** Testing array_fill() : usage variations ***
203--- Testing array_fill() with different object values for 'val' argument ---
204-- Iteration 1 --
205array(2) {
206  [0]=>
207  object(Test)#%d (0) {
208  }
209  [1]=>
210  object(Test)#%d (0) {
211  }
212}
213-- Iteration 2 --
214array(2) {
215  [0]=>
216  object(Test1)#%d (3) {
217    ["member1"]=>
218    int(100)
219    ["var1"]=>
220    int(30)
221    ["var2"]=>
222    int(101)
223  }
224  [1]=>
225  object(Test1)#%d (3) {
226    ["member1"]=>
227    int(100)
228    ["var1"]=>
229    int(30)
230    ["var2"]=>
231    int(101)
232  }
233}
234-- Iteration 3 --
235array(2) {
236  [0]=>
237  object(Child_test1)#%d (4) {
238    ["member2"]=>
239    int(102)
240    ["member1"]=>
241    int(100)
242    ["var1"]=>
243    int(30)
244    ["var2"]=>
245    int(101)
246  }
247  [1]=>
248  object(Child_test1)#%d (4) {
249    ["member2"]=>
250    int(102)
251    ["member1"]=>
252    int(100)
253    ["var1"]=>
254    int(30)
255    ["var2"]=>
256    int(101)
257  }
258}
259-- Iteration 4 --
260array(2) {
261  [0]=>
262  object(Test2)#%d (3) {
263    ["member1":"Test2":private]=>
264    int(100)
265    ["var1"]=>
266    int(30)
267    ["var2"]=>
268    int(101)
269  }
270  [1]=>
271  object(Test2)#%d (3) {
272    ["member1":"Test2":private]=>
273    int(100)
274    ["var1"]=>
275    int(30)
276    ["var2"]=>
277    int(101)
278  }
279}
280-- Iteration 5 --
281array(2) {
282  [0]=>
283  object(Child_test2)#%d (4) {
284    ["member1":"Child_test2":private]=>
285    int(102)
286    ["var1"]=>
287    int(30)
288    ["var2"]=>
289    int(101)
290    ["member1":"Test2":private]=>
291    int(100)
292  }
293  [1]=>
294  object(Child_test2)#%d (4) {
295    ["member1":"Child_test2":private]=>
296    int(102)
297    ["var1"]=>
298    int(30)
299    ["var2"]=>
300    int(101)
301    ["member1":"Test2":private]=>
302    int(100)
303  }
304}
305-- Iteration 6 --
306array(2) {
307  [0]=>
308  object(Test3)#%d (3) {
309    ["member1":protected]=>
310    int(100)
311    ["var1"]=>
312    int(30)
313    ["var2"]=>
314    int(101)
315  }
316  [1]=>
317  object(Test3)#%d (3) {
318    ["member1":protected]=>
319    int(100)
320    ["var1"]=>
321    int(30)
322    ["var2"]=>
323    int(101)
324  }
325}
326-- Iteration 7 --
327array(2) {
328  [0]=>
329  object(Child_test3)#%d (3) {
330    ["member1":protected]=>
331    int(102)
332    ["var1"]=>
333    int(30)
334    ["var2"]=>
335    int(101)
336  }
337  [1]=>
338  object(Child_test3)#%d (3) {
339    ["member1":protected]=>
340    int(102)
341    ["var1"]=>
342    int(30)
343    ["var2"]=>
344    int(101)
345  }
346}
347-- Iteration 8 --
348array(2) {
349  [0]=>
350  object(Test4)#%d (3) {
351    ["member1"]=>
352    int(100)
353    ["member2":"Test4":private]=>
354    int(101)
355    ["member3":protected]=>
356    int(102)
357  }
358  [1]=>
359  object(Test4)#%d (3) {
360    ["member1"]=>
361    int(100)
362    ["member2":"Test4":private]=>
363    int(101)
364    ["member3":protected]=>
365    int(102)
366  }
367}
368-- Iteration 9 --
369array(2) {
370  [0]=>
371  object(Child_test4)#%d (4) {
372    ["var1"]=>
373    int(103)
374    ["member1"]=>
375    int(100)
376    ["member2":"Test4":private]=>
377    int(101)
378    ["member3":protected]=>
379    int(102)
380  }
381  [1]=>
382  object(Child_test4)#%d (4) {
383    ["var1"]=>
384    int(103)
385    ["member1"]=>
386    int(100)
387    ["member2":"Test4":private]=>
388    int(101)
389    ["member3":protected]=>
390    int(102)
391  }
392}
393-- Iteration 10 --
394array(2) {
395  [0]=>
396  object(ConcreteClass1)#%d (4) {
397    ["member1"]=>
398    NULL
399    ["member2":"AbstractClass":private]=>
400    NULL
401    ["member3":protected]=>
402    NULL
403    ["var1"]=>
404    int(30)
405  }
406  [1]=>
407  object(ConcreteClass1)#%d (4) {
408    ["member1"]=>
409    NULL
410    ["member2":"AbstractClass":private]=>
411    NULL
412    ["member3":protected]=>
413    NULL
414    ["var1"]=>
415    int(30)
416  }
417}
418-- Iteration 11 --
419array(2) {
420  [0]=>
421  object(Template1)#%d (0) {
422  }
423  [1]=>
424  object(Template1)#%d (0) {
425  }
426}
427Done
428