【问题标题】:Can the current method know from what method has been called? [duplicate]当前方法能否知道调用了哪个方法? [复制]
【发布时间】:2012-03-04 01:44:06
【问题描述】:

可能重复:
Caller function in PHP 5?
php: determine where function was called from

让我们说

function item_description(){
    $var = 6;
    description($var);
}

function item_description_extended(){
    $var = 7;
    description($var);
}

function description(){
    if(called_from_item_description){
        echo 6;
    }else{
        echo 7;
    }
}

我知道这个函数没有意义......但我的问题是我是否可以知道什么方法称为descrption()

【问题讨论】:

标签: php function


【解决方案1】:

http://us2.php.net/manual/en/function.debug-backtrace.php

debug_backtrace 会告诉你谁打电话给你

【讨论】:

  • 回溯会告诉你太多。虽然这可行,但不幸的是,我认为函数名称以 debug_ 为前缀是有原因的。我之前做过,经过考虑,意识到这是由于设计选择不佳,问题的根源在其他地方得到了解决。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
相关资源
最近更新 更多