1--TEST--
2Test sizeof() function : object functionality - object with Countable interface
3--SKIPIF--
4<?php
5// Skip the test case if Standard PHP Library(spl) is not installed
6  if( !extension_loaded('spl'))
7  {
8     die('skip spl is not installed');
9  }
10?>
11--FILE--
12<?php
13/* Prototype  : int sizeof($mixed var[, int $mode])
14 * Description: Counts an elements in an array. If Standard PHP library is installed,
15 * it will return the properties of an object.
16 * Source code: ext/standard/basic_functions.c
17 * Alias to functions: count()
18 */
19
20echo "*** Testing sizeof() : object functionality ***\n";
21
22echo "-- Testing sizeof() with an object which implements Countable interface --\n";
23class sizeof_class implements Countable
24{
25  public $member1;
26  private $member2;
27  protected $member3;
28
29  public function count()
30  {
31    return 3; // return the count of member variables in the object
32  }
33}
34
35$obj = new sizeof_class();
36
37echo "-- Testing sizeof() in default mode --\n";
38var_dump( sizeof($obj) );
39echo "-- Testing sizeof() in COUNT_NORMAL mode --\n";
40var_dump( sizeof($obj, COUNT_NORMAL) );
41echo "-- Testing sizeof() in COUNT_RECURSIVE mode --\n";
42var_dump( sizeof($obj, COUNT_RECURSIVE) );
43
44echo "Done";
45?>
46--EXPECTF--
47*** Testing sizeof() : object functionality ***
48-- Testing sizeof() with an object which implements Countable interface --
49-- Testing sizeof() in default mode --
50int(3)
51-- Testing sizeof() in COUNT_NORMAL mode --
52int(3)
53-- Testing sizeof() in COUNT_RECURSIVE mode --
54int(3)
55Done
56