文件自动加载

class omnpay{
      public static function __callStatic($method, $parameters)
    {echo '调用了不存在的静态方法:'.$method.'不存在的这个方法的参数是'. implode(',', $parameters). "\n";    
    }
}
omnpay::create('aaa','bbb');
//调用了不存在的静态方法:create不存在的这个方法的参数是aaa,bbb
call_user_func_array:调用回调函数,并把一个数组参数作为回调函数的参数
function foobar($arg, $arg2) {
    echo __FUNCTION__, " 参数是 $arg and $arg2\n";
}
call_user_func_array("foobar", array("one", "two"));//输出  foobar 参数是 one and two


class foo {
    function bar($arg, $arg2) {
        echo __METHOD__, " 参数是 $arg and $arg2\n";
    }
}
$foo = new foo;
call_user_func_array(array($foo, "bar"), array("three", "four"));//输出  foo::bar 参数是 three and four

 

preg_replace_callback:将$str用正则匹配的每个组的字符经过回调函数处理并返回
$str = 'alipay_aoppage_bcd_lichihua';//alipayAoppage
        $newstr= preg_replace_callback(
            '/_([a-z])/',
            function ($match) {
                echo '<pre>';
                var_dump($match);
                return strtoupper($match[1]);
            },
            $str
        );
echo $newstr;

/*

array(2) {
  [0]=>
  string(2) "_a"
  [1]=>
  string(1) "a"
}
array(2) {
  [0]=>
  string(2) "_b"
  [1]=>
  string(1) "b"
}
array(2) {
  [0]=>
  string(2) "_l"
  [1]=>
  string(1) "l"
}
alipayAoppageBcdLichihua

*/

 

posted @ 2019-02-16 00:06  虚无缥缈的云  阅读(156)  评论(0编辑  收藏  举报