获取上层函数名
class ex {<br />
<br />
public function demo()<br />
{<br />
$this->display();<br />
}<br />
<br />
public function dispaly()<br />
{<br />
// 我在这里要获取调用本方法的 demo 函数名,有什么办法??<br />
}<br />
<br />
}
------解决方案--------------------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();
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
(
)
)
)
Statement: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