1--TEST--
2Test sizeof() function : object functionality - object with 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 an object which implements Countable interface --\n";
15class sizeof_class implements Countable
16{
17  public $member1;
18  private $member2;
19  protected $member3;
20
21  public function count()
22  {
23    return 3; // return the count of member variables in the object
24  }
25}
26
27$obj = new sizeof_class();
28
29echo "-- Testing sizeof() in default mode --\n";
30var_dump( sizeof($obj) );
31echo "-- Testing sizeof() in COUNT_NORMAL mode --\n";
32var_dump( sizeof($obj, COUNT_NORMAL) );
33echo "-- Testing sizeof() in COUNT_RECURSIVE mode --\n";
34var_dump( sizeof($obj, COUNT_RECURSIVE) );
35
36echo "Done";
37?>
38--EXPECT--
39*** Testing sizeof() : object functionality ***
40-- Testing sizeof() with an object which implements Countable interface --
41-- Testing sizeof() in default mode --
42int(3)
43-- Testing sizeof() in COUNT_NORMAL mode --
44int(3)
45-- Testing sizeof() in COUNT_RECURSIVE mode --
46int(3)
47Done
48