Home > Backend Development > PHP Tutorial > 获取下层函数名

获取下层函数名

WBOY
Release: 2016-06-13 12:59:54
Original
1010 people have browsed it

获取上层函数名

class ex {<br />
<br />
public function demo()<br />
{<br />
    $this->display();<br />
}<br />
<br />
public function dispaly()<br />
{<br />
    // 我在这里要获取调用本方法的 demo 函数名,有什么办法??<br />
}<br />
<br />
}
Copy after login

------解决方案--------------------
class ex {<br />
  public function demo() {<br />
    $this->display();<br />
  }<br />
  public function display() {<br />
    // 我在这里要获取调用本方法的 demo 函数名,有什么办法??<br />
    print_r(debug_backtrace());<br />
  }<br />
}<br />
$p = new ex;<br />
$p->demo();
Copy after login
Array
(
    [0] => Array
        (
            [file] => D:\AMP\web\ide_tmp.php
            [line] => 5
            [function] => display
            [class] => ex
            [object] => ex Object
                (
                )

            [type] => ->
            [args] => Array
                (
                )

        )

    [1] => Array
        (
            [file] => D:\AMP\web\ide_tmp.php
            [line] => 13
            [function] => demo
            [class] => ex
            [object] => ex Object
                (
                )

            [type] => ->
            [args] => Array
                (
                )

        )

)

Related labels:
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