1--TEST--
2Test array_map() function : usage variations - object functionality
3--FILE--
4<?php
5/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
6 * Description: Applies the callback to the elements of the given arrays
7 * Source code: ext/standard/array.c
8 */
9
10/*
11 * Testing array_map() for object functionalities:
12 *   1) simple class with variable and method
13 *   2) class without members
14 *   3) class with only one method and no variable
15 *   4) abstract and child class
16 *   5) class with static and final members
17 *   6) interface and implemented class
18 */
19echo "*** Testing array_map() : object functionality ***\n";
20
21echo "-- simple class with public variable and method --\n";
22class SimpleClass
23{
24  public $var1 = 1;
25  public function square($n) {
26    return $n * $n;
27  }
28}
29function test($cb, $args) {
30  echo join('::', $cb) . "\n";
31  var_dump(array_map($cb, $args));
32}
33test(array('SimpleClass', 'square'), array(1, 2));
34
35echo "\n-- simple class with private variable and method --\n";
36class SimpleClassPri
37{
38  private $var1 = 10;
39  private function add($n) {
40    return $var + $n;
41  }
42}
43test(array('SimpleClassPri', 'add'), array(1));
44
45echo "\n-- simple class with protected variable and method --\n";
46class SimpleClassPro
47{
48  protected $var1 = 5;
49  protected function mul($n) {
50    return $var1 * $n;
51  }
52}
53test(array('SimpleClassPro', 'mul'), array(2));
54
55echo "\n-- class without members --\n";
56class EmptyClass
57{
58}
59test(array('EmptyClass'), array(1, 2));
60
61echo "\n-- abstract class --\n";
62abstract class AbstractClass
63{
64  protected $var2 = 5;
65  abstract function emptyFunction();
66}
67
68// class deriving the above abstract class
69class ChildClass extends AbstractClass
70{
71  private $var3;
72  public function emptyFunction() {
73    echo "defined in child\n";
74  }
75}
76test(array('ChildClass', 'emptyFunction'), array(1, 2));
77
78echo "\n-- class with final method --\n";
79class FinalClass
80{
81  private $var4;
82  final function finalMethod() {
83    echo "This function can't be overloaded\n";
84  }
85}
86test(array('FinalClass', 'finalMethod'), array(1, 2));
87
88echo "\n-- class with static members --\n";
89class StaticClass
90{
91  static $var5 = 2;
92  public static function square($n) {
93    return ($n * $n);
94  }
95  private static function cube($n) {
96    return ($n * $n * $n);
97  }
98  protected static function retVal($n)  {
99    return array($n);
100  }
101}
102test(array('StaticClass', 'square'), array(1, 2));
103test(array('StaticClass', 'cube'), array(2));
104test(array('StaticClass', 'retVal'), array(3, 4));
105
106echo "-- class implementing an interface --\n";
107interface myInterface
108{
109  public function toImplement();
110}
111class InterClass implements myInterface
112{
113  public static function square($n) {
114    return ($n * $n);
115  }
116  public function toImplement() {
117    return 1;
118  }
119}
120test(array('InterClass', 'square'), array(1, 2));
121
122?>
123===DONE===
124<?php exit(0); ?>
125--EXPECTF--
126*** Testing array_map() : object functionality ***
127-- simple class with public variable and method --
128SimpleClass::square
129
130Deprecated: array_map() expects parameter 1 to be a valid callback, non-static method SimpleClass::square() should not be called statically in %sarray_map_object1.php on line %d
131array(2) {
132  [0]=>
133  int(1)
134  [1]=>
135  int(4)
136}
137
138-- simple class with private variable and method --
139SimpleClassPri::add
140
141Warning: array_map() expects parameter 1 to be a valid callback, cannot access private method SimpleClassPri::add() in %sarray_map_object1.php on line %d
142NULL
143
144-- simple class with protected variable and method --
145SimpleClassPro::mul
146
147Warning: array_map() expects parameter 1 to be a valid callback, cannot access protected method SimpleClassPro::mul() in %sarray_map_object1.php on line %d
148NULL
149
150-- class without members --
151EmptyClass
152
153Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in %sarray_map_object1.php on line %d
154NULL
155
156-- abstract class --
157ChildClass::emptyFunction
158
159Deprecated: array_map() expects parameter 1 to be a valid callback, non-static method ChildClass::emptyFunction() should not be called statically in %sarray_map_object1.php on line %d
160defined in child
161defined in child
162array(2) {
163  [0]=>
164  NULL
165  [1]=>
166  NULL
167}
168
169-- class with final method --
170FinalClass::finalMethod
171
172Deprecated: array_map() expects parameter 1 to be a valid callback, non-static method FinalClass::finalMethod() should not be called statically in %sarray_map_object1.php on line %d
173This function can't be overloaded
174This function can't be overloaded
175array(2) {
176  [0]=>
177  NULL
178  [1]=>
179  NULL
180}
181
182-- class with static members --
183StaticClass::square
184array(2) {
185  [0]=>
186  int(1)
187  [1]=>
188  int(4)
189}
190StaticClass::cube
191
192Warning: array_map() expects parameter 1 to be a valid callback, cannot access private method StaticClass::cube() in %sarray_map_object1.php on line %d
193NULL
194StaticClass::retVal
195
196Warning: array_map() expects parameter 1 to be a valid callback, cannot access protected method StaticClass::retVal() in %sarray_map_object1.php on line %d
197NULL
198-- class implementing an interface --
199InterClass::square
200array(2) {
201  [0]=>
202  int(1)
203  [1]=>
204  int(4)
205}
206===DONE===
207