Annotation of embedaddon/php/ext/standard/tests/array/array_fill_variation3.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_fill() function : usage variations - unexpected values for 'val' argument
3: --FILE--
4: <?php
5: /* Prototype : array array_fill(int $start_key, int $num, mixed $val)
6: * Description: Create an array containing num elements starting with index start_key each initialized to val
7: * Source code: ext/standard/array.c
8: */
9:
10: /*
11: * testing array_fill() by passing different unexpected values for 'val' argument
12: */
13:
14: echo "*** Testing array_fill() : usage variations ***\n";
15:
16: // Initialise function arguments not being substituted
17: $start_key = 0;
18: $num = 2;
19:
20: //get an unset variable
21: $unset_var = 10;
22: unset ($unset_var);
23:
24: // define a class
25: class test
26: {
27: var $t = 10;
28: function __toString()
29: {
30: return "testObject";
31: }
32: }
33:
34:
35: //array of different values for 'val' argument
36: $values = array(
37: // empty string
38: /* 1 */ "",
39: '',
40: // objects
41: /* 3 */ new test(),
42:
43: // undefined variable
44: @$undefined_var,
45:
46: // unset variable
47: /* 5 */ @$unset_var,
48: );
49:
50: // loop through each element of the array for 'val' argument
51: // check the working of array_fill()
52: echo "--- Testing array_fill() with different values for 'val' argument ---\n";
53: $counter = 1;
54: for($index = 0; $index < count($values); $index ++)
55: {
56: echo "-- Iteration $counter --\n";
57: $val = $values[$index];
58:
59: var_dump( array_fill($start_key , $num , $val) );
60:
61: $counter++;
62: }
63:
64: echo"Done";
65: ?>
66: --EXPECTF--
67: *** Testing array_fill() : usage variations ***
68: --- Testing array_fill() with different values for 'val' argument ---
69: -- Iteration 1 --
70: array(2) {
71: [0]=>
72: string(0) ""
73: [1]=>
74: string(0) ""
75: }
76: -- Iteration 2 --
77: array(2) {
78: [0]=>
79: string(0) ""
80: [1]=>
81: string(0) ""
82: }
83: -- Iteration 3 --
84: array(2) {
85: [0]=>
86: object(test)#%d (1) {
87: ["t"]=>
88: int(10)
89: }
90: [1]=>
91: object(test)#%d (1) {
92: ["t"]=>
93: int(10)
94: }
95: }
96: -- Iteration 4 --
97: array(2) {
98: [0]=>
99: NULL
100: [1]=>
101: NULL
102: }
103: -- Iteration 5 --
104: array(2) {
105: [0]=>
106: NULL
107: [1]=>
108: NULL
109: }
110: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>