1--TEST--
2Test sizeof() function : basic functionality - for non-scalar type(array)
3--FILE--
4<?php
5/* Prototype  : int sizeof(mixed $var[, int $mode] )
6 * Description: Counts an elements in an array. If Standard PHP library is
7 *              installed, it will return the properties of an object.
8 * Source code: ext/standard/basic_functions.c
9 * Alias to functions: count()
10 */
11
12/* Testing the sizeof() for non-scalar type(array) value
13 * in default, COUNT_NORMAL and COUNT_RECURSIVE modes.
14 * Sizeof() has been tested for simple integer, string,
15 * indexed and mixed arrays.
16 */
17
18echo "*** Testing sizeof() : basic functionality ***\n";
19
20$int_array = array(1, 2, 3, 4);
21$string_array = array("Saffron", "White", "Green");
22$indexed_array = array("Aggression" => "Saffron", "Peace" => "White", "Growth" => "Green");
23$mixed_array = array(1, 2, "Aggression" => "Saffron", 10 => "Ten", "Ten" => 10);
24
25echo "-- Testing sizeof() with integer array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n";
26echo "default mode: ";
27var_dump( sizeof($int_array) );
28echo "\n";
29echo "COUNT_NORMAL mode: ";
30var_dump( sizeof($int_array, COUNT_NORMAL) );
31echo "\n";
32echo "COUNT_RECURSIVE mode: ";
33var_dump( sizeof($int_array, COUNT_RECURSIVE) );
34echo "\n";
35
36echo "-- Testing sizeof() with string array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n";
37echo "default mode: ";
38var_dump( sizeof($string_array) );
39echo "\n";
40echo "COUNT_NORMAL mode: ";
41var_dump( sizeof($string_array, COUNT_NORMAL) );
42echo "\n";
43echo "COUNT_RECURSIVE mode: ";
44var_dump( sizeof($string_array, COUNT_RECURSIVE) );
45echo "\n";
46
47echo "-- Testing sizeof() with indexed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n";
48echo "default mode: ";
49var_dump( sizeof($indexed_array) );
50echo "\n";
51echo "COUNT_NORMAL mode: ";
52var_dump( sizeof($indexed_array, COUNT_NORMAL) );
53echo "\n";
54echo "COUNT_RECURSIVE mode: ";
55var_dump( sizeof($indexed_array, COUNT_RECURSIVE) );
56echo "\n";
57
58echo "-- Testing sizeof() with mixed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n";
59echo "default mode: ";
60var_dump( sizeof($mixed_array) );
61echo "\n";
62echo "COUNT_NORMAL mode: ";
63var_dump( sizeof($mixed_array, COUNT_NORMAL) );
64echo "\n";
65echo "COUNT_RECURSIVE mode: ";
66var_dump( sizeof($mixed_array, COUNT_RECURSIVE) );
67
68echo "Done";
69?>
70--EXPECTF--
71*** Testing sizeof() : basic functionality ***
72-- Testing sizeof() with integer array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --
73default mode: int(4)
74
75COUNT_NORMAL mode: int(4)
76
77COUNT_RECURSIVE mode: int(4)
78
79-- Testing sizeof() with string array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --
80default mode: int(3)
81
82COUNT_NORMAL mode: int(3)
83
84COUNT_RECURSIVE mode: int(3)
85
86-- Testing sizeof() with indexed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --
87default mode: int(3)
88
89COUNT_NORMAL mode: int(3)
90
91COUNT_RECURSIVE mode: int(3)
92
93-- Testing sizeof() with mixed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --
94default mode: int(5)
95
96COUNT_NORMAL mode: int(5)
97
98COUNT_RECURSIVE mode: int(5)
99Done
100