1--TEST--
2Test sizeof() function : object functionality - object with Countable interface
3--FILE--
4<?php
5echo "*** Testing sizeof() : object functionality ***\n";
6
7echo "-- Testing sizeof() with an object which implements Countable interface --\n";
8class sizeof_class implements Countable
9{
10  public $member1;
11  private $member2;
12  protected $member3;
13
14  public function count(): int
15  {
16    return 3; // return the count of member variables in the object
17  }
18}
19
20$obj = new sizeof_class();
21
22echo "-- Testing sizeof() in default mode --\n";
23var_dump( sizeof($obj) );
24echo "-- Testing sizeof() in COUNT_NORMAL mode --\n";
25var_dump( sizeof($obj, COUNT_NORMAL) );
26echo "-- Testing sizeof() in COUNT_RECURSIVE mode --\n";
27var_dump( sizeof($obj, COUNT_RECURSIVE) );
28
29echo "Done";
30?>
31--EXPECT--
32*** Testing sizeof() : object functionality ***
33-- Testing sizeof() with an object which implements Countable interface --
34-- Testing sizeof() in default mode --
35int(3)
36-- Testing sizeof() in COUNT_NORMAL mode --
37int(3)
38-- Testing sizeof() in COUNT_RECURSIVE mode --
39int(3)
40Done
41