summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/sizeof_object2.phpt
blob: e2c0816c6623268d217ddc7fc9b8f9bfaed622b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
--TEST--
Test sizeof() function : object functionality - objects without Countable interface
--FILE--
<?php
/* Prototype  : int sizeof($mixed var[, int $mode] )
 * Description: Counts an elements in an array. If Standard PHP library is installed,
 * it will return the properties of an object.
 * Source code: ext/standard/basic_functions.c
 * Alias to functions: count()
 */

echo "*** Testing sizeof() : object functionality ***\n";

echo "--- Testing sizeof() with objects which doesn't implement Countable interface ---\n";

// class without member
class test
{ 
  // no members
}

// class with only members and with out member functions 
class test1
{
  public $member1;
  var $var1;
  private $member2;
  protected $member3;

  // no member functions
}

// class with only member functions
class test2
{
  // no data members 

  public function display()
  {
    echo " Class Name : test2\n";
  }
}

// child class which inherits parent test2
class child_test2 extends test2
{
  public $child_member1;
  private $child_member2;
}

// abstract class
abstract class abstract_class
{
  public $member1;
  private $member2;
 
  abstract protected function display();
}

// implement abstract 'abstract_class' class
class concrete_class extends abstract_class
{
  protected function display()
  {
    echo " class name is : concrete_class \n ";
  }
}

$objects = array (
  /* 1  */  new test(),
            new test1(),
            new test2(),
            new child_test2(),
  /* 5  */  new concrete_class()
);

$counter = 1;
for($i = 0; $i < count($objects); $i++)
{
  echo "-- Iteration $counter --\n";
  $var = $objects[$i];

  echo "Default Mode: ";
  var_dump( sizeof($var) );
  echo "\n";
  
  echo "COUNT_NORMAL Mode: ";
  var_dump( sizeof($var, COUNT_NORMAL) );
  echo "\n";

  echo "COUNT_RECURSIVE Mode: ";
  var_dump( sizeof($var, COUNT_RECURSIVE) );
  echo "\n";
 
  $counter++;
}

echo "Done";
?>
--EXPECTF--
*** Testing sizeof() : object functionality ***
--- Testing sizeof() with objects which doesn't implement Countable interface ---
-- Iteration 1 --
Default Mode: int(1)

COUNT_NORMAL Mode: int(1)

COUNT_RECURSIVE Mode: int(1)

-- Iteration 2 --
Default Mode: int(1)

COUNT_NORMAL Mode: int(1)

COUNT_RECURSIVE Mode: int(1)

-- Iteration 3 --
Default Mode: int(1)

COUNT_NORMAL Mode: int(1)

COUNT_RECURSIVE Mode: int(1)

-- Iteration 4 --
Default Mode: int(1)

COUNT_NORMAL Mode: int(1)

COUNT_RECURSIVE Mode: int(1)

-- Iteration 5 --
Default Mode: int(1)

COUNT_NORMAL Mode: int(1)

COUNT_RECURSIVE Mode: int(1)

Done