<?php
function foo($function) {
$function(" World");
}
function bar($params) {
echo "Hello".$params;
}
$variable = 'bar';
foo($variable);
这段代码不太靠谱,感觉$variable不好区分是string还是函数
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
匿名函数
如果你想判断一个
$var是否是函数(准确的说是否可被调用),可以使用is_callable($var)这个函数进行判断。或者在定义参数上直接使用function foo(callable $function)进行限制。判断是否存在函数