天涯·西风

古道西风瘦马,夕阳西下,断肠人在天涯!


  • 首页

  • 归档

Hello World

发表于 2016-12-16

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

php函数call_user_fun

发表于 2016-06-07 | 分类于 php

关于php函数 :call_user_fun()

看到好多地方使用call_user_fun(),一直没有使用过。
查询官网以及相关资料了解,以此记之。(示例来源php官网)

此函数为php内置函数,允许用户调用回调函数,并将参数传入

  • 语法

    mixed call_user_func ( callable $callback [, mixed $parameter [, mixed $… ]] )

第一个参数 callback 是被调用的回调函数,其余参数是回调函数的参数

  • 注意

传入call_user_func()的参数不能为引用传递。

  • 返回值

返回回调函数的返回值,如果错误则返回FALSE

示例:
<?php
function barber($type)
{
    echo "You wanted a $type haircut, no problem\n";
}
call_user_func('barber', "mushroom");
call_user_func('barber', "shave");
?>

相关函数 call_user_fun_array()

功能和call_user_fun()类似,调用回调函数,并把一个#数组#参数作为回调函数的参数

注意数组得是索引数组,结果出错则返回false

示例:
<?php
function foobar($arg, $arg2) {
    echo __FUNCTION__, " got $arg and $arg2\n";
}
class foo {
    function bar($arg, $arg2) {
        echo __METHOD__, " got $arg and $arg2\n";
    }
}


// Call the foobar() function with 2 arguments
call_user_func_array("foobar", array("one", "two"));

// Call the $foo->bar() method with 2 arguments
$foo = new foo;
call_user_func_array(array($foo, "bar"), array("three", "four"));
?>

注

在函数中注册有多个回调内容时(如使用 call_user_func() 与 call_user_func_array()),如在前一个回调中有未捕获的异常,其后的将不再被调用。

关于本站

发表于 2016-06-05 | 分类于 description

关于本站

本站采用 hexo框架 + next主题搭建.

相关网站

本站的搭建主要参考了以下资料:

hexo官网

next官网

以及其他一些文章,在此一并感谢,恕不一一列举.

Tianyaxifeng

Tianyaxifeng

古道西风瘦马,夕阳西下,断肠人在天涯!

3 日志
2 分类
3 标签
RSS
github weibo douban zhihu
Links
  • Veekin
  • janyonlee
© 2018 Tianyaxifeng
由 Hexo 强力驱动
|
主题 — NexT.Muse v5.1.4