1--TEST--
2Test array_pad() function : usage variations - possible values for 'pad_value' argument
3--FILE--
4<?php
5/* Prototype  : array array_pad(array $input, int $pad_size, mixed $pad_value)
6 * Description: Returns a copy of input array padded with pad_value to size pad_size
7 * Source code: ext/standard/array.c
8*/
9
10/*
11* Testing array_pad() function for expected behavior by passing
12* different possible values for $pad_value argument.
13* $input and $pad_size arguments take fixed value.
14*/
15
16echo "*** Testing array_pad() : possible values for \$pad_value argument ***\n";
17
18// Initialise $input and $pad_size argument
19$input = array(1, 2);
20$pad_size = 4;
21
22//get an unset variable
23$unset_var = 10;
24unset ($unset_var);
25
26// get a class
27class classA
28{
29  public function __toString() {
30    return "Class A object";
31  }
32}
33
34// heredoc string
35$heredoc = <<<EOT
36hello world
37EOT;
38
39// get a resource variable
40$fp = fopen(__FILE__, "r");
41
42// get a reference variable
43$value = "hello";
44$reference = &$value;
45
46// different values to be passed to $pad_value argument
47$pad_values = array(
48
49       // int data
50/*1*/  0,
51       1,
52       12345,
53       -2345,
54
55       // float data
56/*5*/  10.5,
57       -10.5,
58       12.3456789000e10,
59       12.3456789000E-10,
60      .5,
61
62       // array data
63/*10*/ array(),
64       array(0),
65       array(1),
66       array(1, 2),
67       array('color' => 'red', 'item' => 'pen'),
68
69       // null data
70/*15*/ NULL,
71       null,
72
73       // boolean data
74/*17*/ true,
75       false,
76       TRUE,
77       FALSE,
78
79       // empty data
80/*21*/ "",
81       '',
82
83       // string data
84/*23*/ "string",
85       'string',
86       $heredoc,
87
88       // strings with different white spaces
89/*26*/ "\v\fHello\t world!! \rstring\n",
90       '\v\fHello\t world!! \rstring\n',
91
92       // object data
93/*28*/ new classA(),
94
95       // undefined data
96/*29*/ @$undefined_var,
97
98       // unset data
99/*30*/ @$unset_var,
100
101       // resource variable
102/*31*/ $fp,
103
104       // reference variable
105/*32*/ $reference
106);
107
108// loop through each element of $pad_values to check the behavior of array_pad()
109$iterator = 1;
110foreach($pad_values as $pad_value) {
111  echo "-- Iteration $iterator --\n";
112  var_dump( array_pad($input, $pad_size, $pad_value) );  // positive 'pad_size'
113  var_dump( array_pad($input, -$pad_size, $pad_value) );  // negative 'pad_size'
114  $iterator++;
115};
116
117echo "Done";
118?>
119--EXPECTF--
120*** Testing array_pad() : possible values for $pad_value argument ***
121-- Iteration 1 --
122array(4) {
123  [0]=>
124  int(1)
125  [1]=>
126  int(2)
127  [2]=>
128  int(0)
129  [3]=>
130  int(0)
131}
132array(4) {
133  [0]=>
134  int(0)
135  [1]=>
136  int(0)
137  [2]=>
138  int(1)
139  [3]=>
140  int(2)
141}
142-- Iteration 2 --
143array(4) {
144  [0]=>
145  int(1)
146  [1]=>
147  int(2)
148  [2]=>
149  int(1)
150  [3]=>
151  int(1)
152}
153array(4) {
154  [0]=>
155  int(1)
156  [1]=>
157  int(1)
158  [2]=>
159  int(1)
160  [3]=>
161  int(2)
162}
163-- Iteration 3 --
164array(4) {
165  [0]=>
166  int(1)
167  [1]=>
168  int(2)
169  [2]=>
170  int(12345)
171  [3]=>
172  int(12345)
173}
174array(4) {
175  [0]=>
176  int(12345)
177  [1]=>
178  int(12345)
179  [2]=>
180  int(1)
181  [3]=>
182  int(2)
183}
184-- Iteration 4 --
185array(4) {
186  [0]=>
187  int(1)
188  [1]=>
189  int(2)
190  [2]=>
191  int(-2345)
192  [3]=>
193  int(-2345)
194}
195array(4) {
196  [0]=>
197  int(-2345)
198  [1]=>
199  int(-2345)
200  [2]=>
201  int(1)
202  [3]=>
203  int(2)
204}
205-- Iteration 5 --
206array(4) {
207  [0]=>
208  int(1)
209  [1]=>
210  int(2)
211  [2]=>
212  float(10.5)
213  [3]=>
214  float(10.5)
215}
216array(4) {
217  [0]=>
218  float(10.5)
219  [1]=>
220  float(10.5)
221  [2]=>
222  int(1)
223  [3]=>
224  int(2)
225}
226-- Iteration 6 --
227array(4) {
228  [0]=>
229  int(1)
230  [1]=>
231  int(2)
232  [2]=>
233  float(-10.5)
234  [3]=>
235  float(-10.5)
236}
237array(4) {
238  [0]=>
239  float(-10.5)
240  [1]=>
241  float(-10.5)
242  [2]=>
243  int(1)
244  [3]=>
245  int(2)
246}
247-- Iteration 7 --
248array(4) {
249  [0]=>
250  int(1)
251  [1]=>
252  int(2)
253  [2]=>
254  float(123456789000)
255  [3]=>
256  float(123456789000)
257}
258array(4) {
259  [0]=>
260  float(123456789000)
261  [1]=>
262  float(123456789000)
263  [2]=>
264  int(1)
265  [3]=>
266  int(2)
267}
268-- Iteration 8 --
269array(4) {
270  [0]=>
271  int(1)
272  [1]=>
273  int(2)
274  [2]=>
275  float(1.23456789E-9)
276  [3]=>
277  float(1.23456789E-9)
278}
279array(4) {
280  [0]=>
281  float(1.23456789E-9)
282  [1]=>
283  float(1.23456789E-9)
284  [2]=>
285  int(1)
286  [3]=>
287  int(2)
288}
289-- Iteration 9 --
290array(4) {
291  [0]=>
292  int(1)
293  [1]=>
294  int(2)
295  [2]=>
296  float(0.5)
297  [3]=>
298  float(0.5)
299}
300array(4) {
301  [0]=>
302  float(0.5)
303  [1]=>
304  float(0.5)
305  [2]=>
306  int(1)
307  [3]=>
308  int(2)
309}
310-- Iteration 10 --
311array(4) {
312  [0]=>
313  int(1)
314  [1]=>
315  int(2)
316  [2]=>
317  array(0) {
318  }
319  [3]=>
320  array(0) {
321  }
322}
323array(4) {
324  [0]=>
325  array(0) {
326  }
327  [1]=>
328  array(0) {
329  }
330  [2]=>
331  int(1)
332  [3]=>
333  int(2)
334}
335-- Iteration 11 --
336array(4) {
337  [0]=>
338  int(1)
339  [1]=>
340  int(2)
341  [2]=>
342  array(1) {
343    [0]=>
344    int(0)
345  }
346  [3]=>
347  array(1) {
348    [0]=>
349    int(0)
350  }
351}
352array(4) {
353  [0]=>
354  array(1) {
355    [0]=>
356    int(0)
357  }
358  [1]=>
359  array(1) {
360    [0]=>
361    int(0)
362  }
363  [2]=>
364  int(1)
365  [3]=>
366  int(2)
367}
368-- Iteration 12 --
369array(4) {
370  [0]=>
371  int(1)
372  [1]=>
373  int(2)
374  [2]=>
375  array(1) {
376    [0]=>
377    int(1)
378  }
379  [3]=>
380  array(1) {
381    [0]=>
382    int(1)
383  }
384}
385array(4) {
386  [0]=>
387  array(1) {
388    [0]=>
389    int(1)
390  }
391  [1]=>
392  array(1) {
393    [0]=>
394    int(1)
395  }
396  [2]=>
397  int(1)
398  [3]=>
399  int(2)
400}
401-- Iteration 13 --
402array(4) {
403  [0]=>
404  int(1)
405  [1]=>
406  int(2)
407  [2]=>
408  array(2) {
409    [0]=>
410    int(1)
411    [1]=>
412    int(2)
413  }
414  [3]=>
415  array(2) {
416    [0]=>
417    int(1)
418    [1]=>
419    int(2)
420  }
421}
422array(4) {
423  [0]=>
424  array(2) {
425    [0]=>
426    int(1)
427    [1]=>
428    int(2)
429  }
430  [1]=>
431  array(2) {
432    [0]=>
433    int(1)
434    [1]=>
435    int(2)
436  }
437  [2]=>
438  int(1)
439  [3]=>
440  int(2)
441}
442-- Iteration 14 --
443array(4) {
444  [0]=>
445  int(1)
446  [1]=>
447  int(2)
448  [2]=>
449  array(2) {
450    ["color"]=>
451    string(3) "red"
452    ["item"]=>
453    string(3) "pen"
454  }
455  [3]=>
456  array(2) {
457    ["color"]=>
458    string(3) "red"
459    ["item"]=>
460    string(3) "pen"
461  }
462}
463array(4) {
464  [0]=>
465  array(2) {
466    ["color"]=>
467    string(3) "red"
468    ["item"]=>
469    string(3) "pen"
470  }
471  [1]=>
472  array(2) {
473    ["color"]=>
474    string(3) "red"
475    ["item"]=>
476    string(3) "pen"
477  }
478  [2]=>
479  int(1)
480  [3]=>
481  int(2)
482}
483-- Iteration 15 --
484array(4) {
485  [0]=>
486  int(1)
487  [1]=>
488  int(2)
489  [2]=>
490  NULL
491  [3]=>
492  NULL
493}
494array(4) {
495  [0]=>
496  NULL
497  [1]=>
498  NULL
499  [2]=>
500  int(1)
501  [3]=>
502  int(2)
503}
504-- Iteration 16 --
505array(4) {
506  [0]=>
507  int(1)
508  [1]=>
509  int(2)
510  [2]=>
511  NULL
512  [3]=>
513  NULL
514}
515array(4) {
516  [0]=>
517  NULL
518  [1]=>
519  NULL
520  [2]=>
521  int(1)
522  [3]=>
523  int(2)
524}
525-- Iteration 17 --
526array(4) {
527  [0]=>
528  int(1)
529  [1]=>
530  int(2)
531  [2]=>
532  bool(true)
533  [3]=>
534  bool(true)
535}
536array(4) {
537  [0]=>
538  bool(true)
539  [1]=>
540  bool(true)
541  [2]=>
542  int(1)
543  [3]=>
544  int(2)
545}
546-- Iteration 18 --
547array(4) {
548  [0]=>
549  int(1)
550  [1]=>
551  int(2)
552  [2]=>
553  bool(false)
554  [3]=>
555  bool(false)
556}
557array(4) {
558  [0]=>
559  bool(false)
560  [1]=>
561  bool(false)
562  [2]=>
563  int(1)
564  [3]=>
565  int(2)
566}
567-- Iteration 19 --
568array(4) {
569  [0]=>
570  int(1)
571  [1]=>
572  int(2)
573  [2]=>
574  bool(true)
575  [3]=>
576  bool(true)
577}
578array(4) {
579  [0]=>
580  bool(true)
581  [1]=>
582  bool(true)
583  [2]=>
584  int(1)
585  [3]=>
586  int(2)
587}
588-- Iteration 20 --
589array(4) {
590  [0]=>
591  int(1)
592  [1]=>
593  int(2)
594  [2]=>
595  bool(false)
596  [3]=>
597  bool(false)
598}
599array(4) {
600  [0]=>
601  bool(false)
602  [1]=>
603  bool(false)
604  [2]=>
605  int(1)
606  [3]=>
607  int(2)
608}
609-- Iteration 21 --
610array(4) {
611  [0]=>
612  int(1)
613  [1]=>
614  int(2)
615  [2]=>
616  string(0) ""
617  [3]=>
618  string(0) ""
619}
620array(4) {
621  [0]=>
622  string(0) ""
623  [1]=>
624  string(0) ""
625  [2]=>
626  int(1)
627  [3]=>
628  int(2)
629}
630-- Iteration 22 --
631array(4) {
632  [0]=>
633  int(1)
634  [1]=>
635  int(2)
636  [2]=>
637  string(0) ""
638  [3]=>
639  string(0) ""
640}
641array(4) {
642  [0]=>
643  string(0) ""
644  [1]=>
645  string(0) ""
646  [2]=>
647  int(1)
648  [3]=>
649  int(2)
650}
651-- Iteration 23 --
652array(4) {
653  [0]=>
654  int(1)
655  [1]=>
656  int(2)
657  [2]=>
658  string(6) "string"
659  [3]=>
660  string(6) "string"
661}
662array(4) {
663  [0]=>
664  string(6) "string"
665  [1]=>
666  string(6) "string"
667  [2]=>
668  int(1)
669  [3]=>
670  int(2)
671}
672-- Iteration 24 --
673array(4) {
674  [0]=>
675  int(1)
676  [1]=>
677  int(2)
678  [2]=>
679  string(6) "string"
680  [3]=>
681  string(6) "string"
682}
683array(4) {
684  [0]=>
685  string(6) "string"
686  [1]=>
687  string(6) "string"
688  [2]=>
689  int(1)
690  [3]=>
691  int(2)
692}
693-- Iteration 25 --
694array(4) {
695  [0]=>
696  int(1)
697  [1]=>
698  int(2)
699  [2]=>
700  string(11) "hello world"
701  [3]=>
702  string(11) "hello world"
703}
704array(4) {
705  [0]=>
706  string(11) "hello world"
707  [1]=>
708  string(11) "hello world"
709  [2]=>
710  int(1)
711  [3]=>
712  int(2)
713}
714-- Iteration 26 --
715array(4) {
716  [0]=>
717  int(1)
718  [1]=>
719  int(2)
720  [2]=>
721  string(25) "Hello	 world!!
721string
722"
723  [3]=>
724  string(25) "Hello	 world!!
724string
725"
726}
727array(4) {
728  [0]=>
729  string(25) "Hello	 world!!
729string
730"
731  [1]=>
732  string(25) "Hello	 world!!
732string
733"
734  [2]=>
735  int(1)
736  [3]=>
737  int(2)
738}
739-- Iteration 27 --
740array(4) {
741  [0]=>
742  int(1)
743  [1]=>
744  int(2)
745  [2]=>
746  string(30) "\v\fHello\t world!! \rstring\n"
747  [3]=>
748  string(30) "\v\fHello\t world!! \rstring\n"
749}
750array(4) {
751  [0]=>
752  string(30) "\v\fHello\t world!! \rstring\n"
753  [1]=>
754  string(30) "\v\fHello\t world!! \rstring\n"
755  [2]=>
756  int(1)
757  [3]=>
758  int(2)
759}
760-- Iteration 28 --
761array(4) {
762  [0]=>
763  int(1)
764  [1]=>
765  int(2)
766  [2]=>
767  object(classA)#%d (0) {
768  }
769  [3]=>
770  object(classA)#%d (0) {
771  }
772}
773array(4) {
774  [0]=>
775  object(classA)#%d (0) {
776  }
777  [1]=>
778  object(classA)#%d (0) {
779  }
780  [2]=>
781  int(1)
782  [3]=>
783  int(2)
784}
785-- Iteration 29 --
786array(4) {
787  [0]=>
788  int(1)
789  [1]=>
790  int(2)
791  [2]=>
792  NULL
793  [3]=>
794  NULL
795}
796array(4) {
797  [0]=>
798  NULL
799  [1]=>
800  NULL
801  [2]=>
802  int(1)
803  [3]=>
804  int(2)
805}
806-- Iteration 30 --
807array(4) {
808  [0]=>
809  int(1)
810  [1]=>
811  int(2)
812  [2]=>
813  NULL
814  [3]=>
815  NULL
816}
817array(4) {
818  [0]=>
819  NULL
820  [1]=>
821  NULL
822  [2]=>
823  int(1)
824  [3]=>
825  int(2)
826}
827-- Iteration 31 --
828array(4) {
829  [0]=>
830  int(1)
831  [1]=>
832  int(2)
833  [2]=>
834  resource(%d) of type (stream)
835  [3]=>
836  resource(%d) of type (stream)
837}
838array(4) {
839  [0]=>
840  resource(%d) of type (stream)
841  [1]=>
842  resource(%d) of type (stream)
843  [2]=>
844  int(1)
845  [3]=>
846  int(2)
847}
848-- Iteration 32 --
849array(4) {
850  [0]=>
851  int(1)
852  [1]=>
853  int(2)
854  [2]=>
855  string(5) "hello"
856  [3]=>
857  string(5) "hello"
858}
859array(4) {
860  [0]=>
861  string(5) "hello"
862  [1]=>
863  string(5) "hello"
864  [2]=>
865  int(1)
866  [3]=>
867  int(2)
868}
869Done
870