1--TEST-- 2Calling method from array 3--FILE-- 4<?php 5 6class Hello { 7 public function world($x) { 8 echo "Hello, $x\n"; return $this; 9 } 10} 11 12class Hello2 { 13 static public function world($x) { 14 echo "Hello, $x\n"; 15 } 16} 17 18class Magic { 19 public function __call($f, $a) { 20 printf("%s called (%s)!\n", __METHOD__, $f); 21 } 22} 23 24class Magic2 { 25 public static function __callStatic($f, $a) { 26 printf("%s called (%s)!\n", __METHOD__, $f); 27 } 28} 29 30class Magic3 { 31 public static function __callStatic($f, $a) { 32 printf("%s called (%s)!\n", __METHOD__, $f); 33 } 34 public function __call($f, $a) { 35 printf("%s called (%s)!\n", __METHOD__, $f); 36 } 37} 38 39$f = array('Hello','world'); 40var_dump($f('you')); 41var_dump(call_user_func($f, 'you')); 42 43printf("-----\n"); 44 45$h= new Hello; 46$f = array($h,'world'); 47var_dump($f('again')); 48var_dump(call_user_func($f, 'again')); 49 50printf("-----\n"); 51 52function bar() { 53 return array(new Hello,'world'); 54} 55$f = bar(); 56var_dump($f('there')); 57var_dump(call_user_func($f, 'there')); 58 59printf("-----\n"); 60 61$x = function ($c,$v) { return array($c, $v); }; 62 63$c = new Hello; 64$m = 'world'; 65$f = $x($c, $m); 66var_dump($f('devs')); 67var_dump(call_user_func($f, 'devs')); 68 69printf("-----\n"); 70 71$f = array(new Magic, 'foo'); 72$f(); 73call_user_func($f); 74 75printf("-----\n"); 76 77$f = array('Magic2', 'foo'); 78$f(); 79call_user_func($f); 80 81 82printf("-----\n"); 83 84$f = array('Magic3', 'foo'); 85$f(); 86call_user_func($f); 87 88printf("-----\n"); 89 90$f = array(new Magic3, 'foo'); 91$f(); 92call_user_func($f); 93 94printf("-----\n"); 95 96$f = array(new Hello2, 'world'); 97var_dump($f('you')); 98var_dump(call_user_func($f, 'you')); 99 100?> 101--EXPECTF-- 102Strict Standards: Non-static method Hello::world() should not be called statically in %s on line %d 103Hello, you 104 105Notice: Undefined variable: this in %s on line %d 106NULL 107 108Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method Hello::world() should not be called statically in %s on line %d 109Hello, you 110 111Notice: Undefined variable: this in %s on line %d 112NULL 113----- 114Hello, again 115object(Hello)#1 (0) { 116} 117Hello, again 118object(Hello)#1 (0) { 119} 120----- 121Hello, there 122object(Hello)#2 (0) { 123} 124Hello, there 125object(Hello)#2 (0) { 126} 127----- 128Hello, devs 129object(Hello)#4 (0) { 130} 131Hello, devs 132object(Hello)#4 (0) { 133} 134----- 135Magic::__call called (foo)! 136Magic::__call called (foo)! 137----- 138Magic2::__callStatic called (foo)! 139Magic2::__callStatic called (foo)! 140----- 141Magic3::__callStatic called (foo)! 142Magic3::__callStatic called (foo)! 143----- 144Magic3::__call called (foo)! 145Magic3::__call called (foo)! 146----- 147Hello, you 148NULL 149Hello, you 150NULL 151