1--TEST--
2Test sizeof() function : object functionality - objects without Countable interface
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 installed,
7 * it will return the properties of an object.
8 * Source code: ext/standard/basic_functions.c
9 * Alias to functions: count()
10 */
11
12echo "*** Testing sizeof() : object functionality ***\n";
13
14echo "--- Testing sizeof() with objects which doesn't implement Countable interface ---\n";
15
16// class without member
17class test
18{
19  // no members
20}
21
22// class with only members and with out member functions
23class test1
24{
25  public $member1;
26  var $var1;
27  private $member2;
28  protected $member3;
29
30  // no member functions
31}
32
33// class with only member functions
34class test2
35{
36  // no data members
37
38  public function display()
39  {
40    echo " Class Name : test2\n";
41  }
42}
43
44// child class which inherits parent test2
45class child_test2 extends test2
46{
47  public $child_member1;
48  private $child_member2;
49}
50
51// abstract class
52abstract class abstract_class
53{
54  public $member1;
55  private $member2;
56
57  abstract protected function display();
58}
59
60// implement abstract 'abstract_class' class
61class concrete_class extends abstract_class
62{
63  protected function display()
64  {
65    echo " class name is : concrete_class \n ";
66  }
67}
68
69$objects = array (
70  /* 1  */  new test(),
71            new test1(),
72            new test2(),
73            new child_test2(),
74  /* 5  */  new concrete_class()
75);
76
77$counter = 1;
78for($i = 0; $i < count($objects); $i++)
79{
80  echo "-- Iteration $counter --\n";
81  $var = $objects[$i];
82
83  echo "Default Mode: ";
84  var_dump( sizeof($var) );
85  echo "\n";
86
87  echo "COUNT_NORMAL Mode: ";
88  var_dump( sizeof($var, COUNT_NORMAL) );
89  echo "\n";
90
91  echo "COUNT_RECURSIVE Mode: ";
92  var_dump( sizeof($var, COUNT_RECURSIVE) );
93  echo "\n";
94
95  $counter++;
96}
97
98echo "Done";
99?>
100--EXPECTF--
101*** Testing sizeof() : object functionality ***
102--- Testing sizeof() with objects which doesn't implement Countable interface ---
103-- Iteration 1 --
104Default Mode: int(1)
105
106COUNT_NORMAL Mode: int(1)
107
108COUNT_RECURSIVE Mode: int(1)
109
110-- Iteration 2 --
111Default Mode: int(1)
112
113COUNT_NORMAL Mode: int(1)
114
115COUNT_RECURSIVE Mode: int(1)
116
117-- Iteration 3 --
118Default Mode: int(1)
119
120COUNT_NORMAL Mode: int(1)
121
122COUNT_RECURSIVE Mode: int(1)
123
124-- Iteration 4 --
125Default Mode: int(1)
126
127COUNT_NORMAL Mode: int(1)
128
129COUNT_RECURSIVE Mode: int(1)
130
131-- Iteration 5 --
132Default Mode: int(1)
133
134COUNT_NORMAL Mode: int(1)
135
136COUNT_RECURSIVE Mode: int(1)
137
138Done
139