2011/6/5 Benjamin Eberlei <kont...@beberlei.de>

> That can lead to quite a bit of simplifications in code where you now have
> to check for is_array/is_callable/instanceof Closure and such. I like it.
>
>
Exactly, and since our current $x = 'hello::world'; $x(); doesn't support
method calls, the array one can help on this just like the call_user_func()
approach with arrays.

<?php

class Hello {
   static public function world($x) {
     echo "Hello, $x\n";
   }
}

function hello_world($x) {
   echo "Hello, $x\n";
}

$callbacks = array(
   array('Hello', 'world'),
   function ($x) { echo "Hello, $x\n"; },
   'hello_world'
);

foreach ($callbacks as $k => $callback) {
   if (is_callable($callback)) {
     $callback($k);
   }
}

Output:
Hello, 0
Hello, 1
Hello, 2

-- 
Regards,
Felipe Pena

Reply via email to