请问,PHP里如何获取一个函数是被哪个函数调用的?
例如:
function a(){
c();
}
function b(){
c();
}
function c(){
}
调用:b();,请问我在c()里面要用什么函数或方法来获得调用者是b函数注:在c()函数传调用者函数名称的方式不是我想要的。
高手请指教...
例如:
function a(){
c();
}
function b(){
c();
}
function c(){
}
调用:b();,请问我在c()里面要用什么函数或方法来获得调用者是b函数注:在c()函数传调用者函数名称的方式不是我想要的。
高手请指教...
ps:lz是要实现什么啊,传参不符合需求么?
b();
}function b() {
$backtrace = debug_backtrace();
array_shift($backtrace);
var_dump($backtrace);
}a();
http://www.php.net/manual/en/function.debug-backtrace.php
=========================================================
Example #1 debug_backtrace() example<?php
// filename: /tmp/a.phpfunction a_test($str)
{
echo "\nHi: $str";
var_dump(debug_backtrace());
}a_test('friend');
?><?php
// filename: /tmp/b.php
include_once '/tmp/a.php';
?>
Results similar to the following when executing /tmp/b.php: Hi: friend
array(2) {
[0]=>
array(4) {
["file"] => string(10) "/tmp/a.php"
["line"] => int(10)
["function"] => string(6) "a_test" <= 这里
["args"]=>
array(1) {
[0] => &string(6) "friend"
}
}
[1]=>
array(4) {
["file"] => string(10) "/tmp/b.php"
["line"] => int(2)
["args"] =>
array(1) {
[0] => string(10) "/tmp/a.php"
}
["function"] => string(12) "include_once"
}
}