Home > Backend Development > PHP Tutorial > php 如何引用一个函数名,不是调用?

php 如何引用一个函数名,不是调用?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:13:43
Original
976 people have browsed it

<code>    class c{
      function f1($parameter){
    
      }
    
      function f2(){
        $f = #如何获得f1的引用?
        $f($input);#为了这个
      }
    }</code>
Copy after login
Copy after login

回复内容:

<code>    class c{
      function f1($parameter){
    
      }
    
      function f2(){
        $f = #如何获得f1的引用?
        $f($input);#为了这个
      }
    }</code>
Copy after login
Copy after login

array($this, 'f1');

也可以用$f = array('c', 'f1');

其实就是个callable类型,callable类型有3种传递方法.
1.传递函数名(函数不等于方法)
2.传递数组,其中第一个元素是一个实例,第二个元素是实例当中的方法
3.传递数组,其中第一个元素是类名,第二个元素是实例当中的静态方法

function f2(){
        call_user_func(['c','f1'],$input);
         
      }
Copy after login

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template