⬆️ ⬇️

is_callable works correctly with Closure (PHP 5.3)

The is_callable and call_user_func family of functions correctly work with Closure closures (PHP 5.3) just like anonymous functions. Simple tests:

<?php function is_callable_test(Closure $func=null){ if (is_callable($func)){ $func(); }else{ echo 'uncaleble', "\n"; } } function call_user_func_test($func=null){ if (is_callable($func)){ call_user_func($func, ' second test'); }else{ echo 'uncaleble', "\n"; } } $win_text = 'is_callable function work correctly!'; is_callable_test(function () use ($win_text){ echo $win_text, "\n"; }); $win_text = 'call_user_func work correctly!'; call_user_func_test(function ($num) use ($win_text){ echo $win_text,' ', $num, "\n"; }); ?> 


')

Source: https://habr.com/ru/post/117935/



All Articles