zoukankan      html  css  js  c++  java
  • call_user_func()的参数不能为引用传递 自定义替代方法

    php手册 中关于

    请注意,传入call_user_func()的参数不能为引用传递。
    

    关于这个情况的解释,可自己搜索。我们可以自己定义一个函数解决这样的问题,实例如下:

    <?php
    ini_set('display_errors',1);
    error_reporting(E_ALL);
    
    
    function call_user_func_super($h,&$c)
    {
    	if(is_callable($h))
    	{
    		return (is_array($h))?$h[0]->$h[1]($c):$h($c);
    	}
    	else
    	{
    		return false;
    	}
    }
    
    $c = 1;
    
    $h = function(&$c){
    	echo ++$c;
    };
    call_user_func_super($h,$c);
    echo $c.'<br/>';
    
    
    $h = 'hhh';
    function hhh(&$c){
    	echo ++$c;
    }
    call_user_func_super($h,$c);
    echo $c.'<br/>';
    
    class nnn{
    	function hhh(&$c){
    		echo ++$c;
    	}
    }
    $h = [new nnn,'hhh'];
    call_user_func_super($h,$c);
    echo $c.'<br/>';
    

      其中call_user_func_super就是自定义的 函数,可以使用自定义变量。输出:

    22
    33
    44
    

     

    当然这里面只使用了一个自定义变量,如果多个,可自行更改就可以了。

  • 相关阅读:
    swarm集群搭建 及集群维护操作
    zabbix 告警说明
    yum 下载安装包
    mongdb常见操作
    cloudera5.16.1 离线安装
    centos7 安装hadoop-3.2.1
    rpcbind 启动报错
    ingress-nginx 安装
    Dubbo学习
    mybatis防止SQL注入
  • 原文地址:https://www.cnblogs.com/osfipin/p/6185088.html
Copyright © 2011-2022 走看看