回答:
debug_backtraceを参照してください。これにより、呼び出しスタックを一番上まで追跡できます。
発信者を取得する方法は次のとおりです。
$trace = debug_backtrace();
$caller = $trace[1];
echo "Called by {$caller['function']}";
if (isset($caller['class']))
    echo " in {$caller['class']}";
list(, $caller) = debug_backtrace(false);ために、呼び出し元を取得するために使用しますfalse
                    echo 'called by '.$trace[0]['function']
                    debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];より良いパフォーマンスで発信者名を取得します。
                    Xdebugはいくつかの素晴らしい関数を提供します。
<?php
  Class MyClass
  {
    function __construct(){
        $this->callee();
    }
    function callee() {
        echo sprintf("callee() called @ %s: %s from %s::%s",
            xdebug_call_file(),
            xdebug_call_line(),
            xdebug_call_class(),
            xdebug_call_function()
        );
    }
  }
  $rollDebug = new MyClass();
?>
トレースを返します
callee() called @ /var/www/xd.php: 16 from MyClass::__constructXdebugをubuntuにインストールするには、最善の方法は
sudo aptitude install php5-xdebug最初にphp5-devをインストールする必要があるかもしれません
sudo aptitude install php5-devこれは非常に遅いですが、現在の関数が呼び出される関数の名前を与える関数を共有したいと思います。
public function getCallingFunctionName($completeTrace=false)
    {
        $trace=debug_backtrace();
        if($completeTrace)
        {
            $str = '';
            foreach($trace as $caller)
            {
                $str .= " -- Called by {$caller['function']}";
                if (isset($caller['class']))
                    $str .= " From Class {$caller['class']}";
            }
        }
        else
        {
            $caller=$trace[2];
            $str = "Called by {$caller['function']}";
            if (isset($caller['class']))
                $str .= " From Class {$caller['class']}";
        }
        return $str;
    }
これがお役に立てば幸いです。
debug_backtrace() パラメータの詳細、現在の呼び出しスタック内の関数/メソッド呼び出しを提供します。
これを作って自分で使った
/**
 * Gets the caller of the function where this function is called from
 * @param string what to return? (Leave empty to get all, or specify: "class", "function", "line", "class", etc.) - options see: http://php.net/manual/en/function.debug-backtrace.php
 */
function getCaller($what = NULL)
{
    $trace = debug_backtrace();
    $previousCall = $trace[2]; // 0 is this call, 1 is call in previous function, 2 is caller of that function
    if(isset($what))
    {
        return $previousCall[$what];
    }
    else
    {
        return $previousCall;
    }   
}
floriの方法は常に呼び出し元ではなく呼び出された関数名を返すため、関数として機能しないことを述べたかったのですが、コメントについての評判はありません。私のケースではうまく機能する、フロリの答えに基づいて非常に単純な関数を作成しました。
class basicFunctions{
    public function getCallerFunction(){
        return debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2]['function'];
    }
}
function a($authorisedFunctionsList = array("b")){
    $ref = new basicFunctions;
    $caller = $ref->getCallerFunction();
    if(in_array($caller,$authorisedFunctionsList)):
        echo "Welcome!";
        return true;
    else:
        echo "Unauthorised caller!";
        return false; 
    endif;
}
function b(){
    $executionContinues = $this->a();
    $executionContinues or exit;
    //Do something else..
}
debug_backtraceによって返された配列からこの情報を抽出できます
これは私にとって最もうまくいきました: var_dump(debug_backtrace());
実際、私はdebug_print_backtrace()があなたが必要とするものを実行すると思います。 http://php.net/manual/en/function.debug-print-backtrace.php
これはうまくいきます:
// Outputs an easy to read call trace
// Credit: https://www.php.net/manual/en/function.debug-backtrace.php#112238
// Gist: https://gist.github.com/UVLabs/692e542d3b53e079d36bc53b4ea20a4b
Class MyClass{
public function generateCallTrace()
{
    $e = new Exception();
    $trace = explode("\n", $e->getTraceAsString());
    // reverse array to make steps line up chronologically
    $trace = array_reverse($trace);
    array_shift($trace); // remove {main}
    array_pop($trace); // remove call to this method
    $length = count($trace);
    $result = array();
   
    for ($i = 0; $i < $length; $i++)
    {
        $result[] = ($i + 1)  . ')' . substr($trace[$i], strpos($trace[$i], ' ')); // replace '#someNum' with '$i)', set the right ordering
    }
   
    return "\t" . implode("\n\t", $result);
}
}
// call function where needed to output call trace
/**
Example output:
1) /var/www/test/test.php(15): SomeClass->__construct()
2) /var/www/test/SomeClass.class.php(36): SomeClass->callSomething()
**/```