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