summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/sizeof_basic2.phpt
blob: 3dfbc7c662367034a3b77c10c74c2fb22738443c (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
--TEST--
Test sizeof() function : basic functionality - for non-scalar type(array)
--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()
 */

/* Testing the sizeof() for non-scalar type(array) value
 * in default, COUNT_NORMAL and COUNT_RECURSIVE modes.
 * Sizeof() has been tested for simple integer, string,
 * indexed and mixed arrays.
 */

echo "*** Testing sizeof() : basic functionality ***\n";

$int_array = array(1, 2, 3, 4);
$string_array = array("Saffron", "White", "Green");
$indexed_array = array("Aggression" => "Saffron", "Peace" => "White", "Growth" => "Green");
$mixed_array = array(1, 2, "Aggression" => "Saffron", 10 => "Ten", "Ten" => 10);

echo "-- Testing sizeof() with integer array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n";
echo "default mode: ";
var_dump( sizeof($int_array) );
echo "\n";
echo "COUNT_NORMAL mode: ";
var_dump( sizeof($int_array, COUNT_NORMAL) );
echo "\n";
echo "COUNT_RECURSIVE mode: ";
var_dump( sizeof($int_array, COUNT_RECURSIVE) );
echo "\n";

echo "-- Testing sizeof() with string array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n";
echo "default mode: ";
var_dump( sizeof($string_array) );
echo "\n";
echo "COUNT_NORMAL mode: ";
var_dump( sizeof($string_array, COUNT_NORMAL) );
echo "\n";
echo "COUNT_RECURSIVE mode: ";
var_dump( sizeof($string_array, COUNT_RECURSIVE) );
echo "\n";

echo "-- Testing sizeof() with indexed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n";
echo "default mode: ";
var_dump( sizeof($indexed_array) );
echo "\n";
echo "COUNT_NORMAL mode: ";
var_dump( sizeof($indexed_array, COUNT_NORMAL) );
echo "\n";
echo "COUNT_RECURSIVE mode: ";
var_dump( sizeof($indexed_array, COUNT_RECURSIVE) );
echo "\n";

echo "-- Testing sizeof() with mixed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n";
echo "default mode: ";
var_dump( sizeof($mixed_array) );
echo "\n";
echo "COUNT_NORMAL mode: ";
var_dump( sizeof($mixed_array, COUNT_NORMAL) );
echo "\n";
echo "COUNT_RECURSIVE mode: ";
var_dump( sizeof($mixed_array, COUNT_RECURSIVE) );

echo "Done";
?>
--EXPECTF--
*** Testing sizeof() : basic functionality ***
-- Testing sizeof() with integer array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --
default mode: int(4)

COUNT_NORMAL mode: int(4)

COUNT_RECURSIVE mode: int(4)

-- Testing sizeof() with string array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --
default mode: int(3)

COUNT_NORMAL mode: int(3)

COUNT_RECURSIVE mode: int(3)

-- Testing sizeof() with indexed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --
default mode: int(3)

COUNT_NORMAL mode: int(3)

COUNT_RECURSIVE mode: int(3)

-- Testing sizeof() with mixed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --
default mode: int(5)

COUNT_NORMAL mode: int(5)

COUNT_RECURSIVE mode: int(5)
Done