php回调函数主要用在什么场景?
最近在研究回调函数,据说是变身高级程序员必备技能之一,网上搜了大半天,到现在一直也没搞清楚回调使用的真正场景,遂在公司的laravel项目中以call_user_func为关键字搜了下,N多回调,没看懂,以下面代码为例:
/**
* Asserts that a haystack that is stored in a static attribute of a class
* or an attribute of an object contains a needle.
*
* @param mixed $needle
* @param string $haystackAttributeName
* @param mixed $haystackClassOrObject
* @param string $message
* @param bool $ignoreCase
* @param bool $checkForObjectIdentity
* @param bool $checkForNonObjectIdentity
*/
function assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false)
{
return call_user_func_array(
'PHPUnit_Framework_Assert::assertAttributeContains',
func_get_args()
);
}
这段代码使用了回调,但是搞不清楚不能正常的写吗?如下:
function assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false)
{
return PHPUnit_Framework_Assert::assertAttributeContains(func_get_args());
}
为何不用这种直接调用而非得用回调呢?感觉有点装逼。
请大神指点,多谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(5)
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
参考相同问题