1--TEST--
2Test array_filter() function : object functionality
3--FILE--
4<?php
5/* This file uses 'input' array with different types of objects and passes
6 * it to array_filter() to test object functionality
7 * i.e. object of simple class with members and functions
8 * object of empty class
9 * object of child class extending abstract class
10 * object of class containing static member
11 */
12
13echo "*** Testing array_filter() : object functionality ***\n";
14
15// simple class with members - variable and method
16class SimpleClass
17{
18  public $var1 = 10;
19  public function check() {
20    return $var1;
21  }
22}
23
24// class without members
25class EmptyClass
26{
27}
28
29// abstract class
30abstract class AbstractClass
31{
32  protected $var2 = 5;
33  abstract function emptyMethod();
34}
35
36// class deriving above abstract class
37class ChildClass extends AbstractClass
38{
39  private $var3;
40  public function emptyMethod() {
41    echo "defined in child";
42  }
43}
44
45// class with final method
46class FinalClass
47{
48  private $var4;
49  final function finalMethod() {
50    echo 'This cannot be overloaded';
51  }
52}
53
54// class with static members
55class StaticClass
56{
57  static $var5 = 5;
58  public static function staticMethod() {
59    echo 'this is static method';
60  }
61}
62
63function always_true($input)
64{
65  return true;
66}
67
68// Callback function which returns always false
69function always_false($input)
70{
71  return false;
72}
73
74// 'input' array containing objects as elements
75$input = array(
76  new SimpleClass(),
77  new EmptyClass(),
78  new ChildClass(),
79  new FinalClass(),
80  new StaticClass()
81);
82
83
84// with default callback
85var_dump( array_filter($input) );
86
87// with always_true callback function
88var_dump( array_filter($input, "always_true") );
89
90// with always_false callback function
91var_dump( array_filter($input, "always_false") );
92
93echo "Done"
94?>
95--EXPECTF--
96*** Testing array_filter() : object functionality ***
97array(5) {
98  [0]=>
99  object(SimpleClass)#%d (1) {
100    ["var1"]=>
101    int(10)
102  }
103  [1]=>
104  object(EmptyClass)#%d (0) {
105  }
106  [2]=>
107  object(ChildClass)#%d (2) {
108    ["var2":protected]=>
109    int(5)
110    ["var3":"ChildClass":private]=>
111    NULL
112  }
113  [3]=>
114  object(FinalClass)#%d (1) {
115    ["var4":"FinalClass":private]=>
116    NULL
117  }
118  [4]=>
119  object(StaticClass)#%d (0) {
120  }
121}
122array(5) {
123  [0]=>
124  object(SimpleClass)#%d (1) {
125    ["var1"]=>
126    int(10)
127  }
128  [1]=>
129  object(EmptyClass)#%d (0) {
130  }
131  [2]=>
132  object(ChildClass)#%d (2) {
133    ["var2":protected]=>
134    int(5)
135    ["var3":"ChildClass":private]=>
136    NULL
137  }
138  [3]=>
139  object(FinalClass)#%d (1) {
140    ["var4":"FinalClass":private]=>
141    NULL
142  }
143  [4]=>
144  object(StaticClass)#%d (0) {
145  }
146}
147array(0) {
148}
149Done
150