Home > Backend Development > PHP Tutorial > php 引用一个函数?

php 引用一个函数?

WBOY
Release: 2016-06-06 20:14:13
Original
998 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

$f=$this->f1();

少打了括号

<code><?php class c{
  function f1(){
        echo 'hello';
  }

  function f2(){
    $f = $this->f1();
    $f;
  }
}

$i =new c;

$i->f2();
</code>
Copy after login

<code>class c{
  function f1($parameter){

  }

  function f2(){
    $this->$f1($input);
  }
}</code>
Copy after login
Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template