summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/sizeof_variation5.phpt
blob: 1c487045c653bc7e6663ee2e409061f2b02c96d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
--TEST--
Test sizeof() function : usage variations - different values for 'mode' argument
--FILE--
<?php
/* Prototype  : int sizeof($mixed var[, int $mode])
 * Description: Counts an elements in an array. If Standard PHP library is installed,
 * it will return the properties of an object.
 * Source code: ext/standard/basic_functions.c
 * Alias to functions: count()
 */

echo "*** Testing sizeof() : usage variations ***\n";

echo "--- Testing sizeof() with different values for 'mode' argument ---\n";
$array1 = array(1, 2, 3, 4, array(1.0, 2.0, array()), array() );

// get a resource variable
$fp = fopen(__FILE__, "r");

//unset variable
$unset_var = 10;
unset($unset_var);

//class declaration
class test
{
  public $member1;
}

$mode_values = array (
  /* 1  */  COUNT_NORMAL,
            COUNT_RECURSIVE,
            0,  // same as COUNT_NORMAL
            1,  // same as COUNT_RECURSIVE

  /* 5  */  TRUE,  // same as COUNT_RECURSIVE
            true,  // same as COUNT_RECURSIVE
            FALSE, // same as COUNT_NORMAL
            false, // same as COUNT_NORMAL
            NULL,  // same as COUNT_NORMAL
  /* 10 */  null,  // same as COUNT_NORMAL
            100,
            10.5,
            12.34e3,
            12.34E-2,
  /* 15 */  .5,
            "",
            '',
            "string",
            'string',
  /* 20 */  @$unset_var,
            new test(),
  /* 22 */  $fp
);

// loop through the each element of $modes_array for 'mode' argument
// and check the working of sizeof()
$counter = 1;
for($i = 0; $i < count($mode_values); $i++)
{
  echo "-- Iteration $counter --\n";
  $mode = $mode_values[$i];

  var_dump( sizeof($array1, $mode) );

  $counter++;
}

fclose($fp);

echo "Done";
?>
--EXPECTF--
*** Testing sizeof() : usage variations ***
--- Testing sizeof() with different values for 'mode' argument ---
-- Iteration 1 --
int(6)
-- Iteration 2 --
int(9)
-- Iteration 3 --
int(6)
-- Iteration 4 --
int(9)
-- Iteration 5 --
int(9)
-- Iteration 6 --
int(9)
-- Iteration 7 --
int(6)
-- Iteration 8 --
int(6)
-- Iteration 9 --
int(6)
-- Iteration 10 --
int(6)
-- Iteration 11 --
int(6)
-- Iteration 12 --
int(6)
-- Iteration 13 --
int(6)
-- Iteration 14 --
int(6)
-- Iteration 15 --
int(6)
-- Iteration 16 --

Warning: sizeof() expects parameter 2 to be integer, string given in %s on line %d
NULL
-- Iteration 17 --

Warning: sizeof() expects parameter 2 to be integer, string given in %s on line %d
NULL
-- Iteration 18 --

Warning: sizeof() expects parameter 2 to be integer, string given in %s on line %d
NULL
-- Iteration 19 --

Warning: sizeof() expects parameter 2 to be integer, string given in %s on line %d
NULL
-- Iteration 20 --
int(6)
-- Iteration 21 --

Warning: sizeof() expects parameter 2 to be integer, object given in %s on line %d
NULL
-- Iteration 22 --

Warning: sizeof() expects parameter 2 to be integer, resource given in %s on line %d
NULL
Done