0

Possible Duplicate:
Caller function in PHP 5?
php: determine where function was called from

Lets say

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;
    }
}

I know this functions make no sense... but my question here is if i can know what method called descrption()?

Community
  • 1
  • 1
Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378
  • 2
    Please see http://stackoverflow.com/questions/190421/caller-function-in-php-5 – Telmo Marques Mar 03 '12 at 17:43
  • I believe no, but you can keep state in session, global var or something and write/read function's name from there, but it's kind of messy – dotoree Mar 03 '12 at 17:45

1 Answers1

2

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

debug_backtrace will tell who called you

dldnh
  • 8,923
  • 3
  • 40
  • 52
  • Backtracing will tell you *too* much. While this works, unfortunately I believe the function name is prefixed with `debug_` for a reason. I've done this before, and after consideration, realized it was due to poor design choices, and the root of the problem was solved elsewhere. – Dan Lugg Mar 03 '12 at 18:34