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