PHP 5中的调用者函数?是否有PHP函数来查找给定函数中调用方函数的名称?
                    
                    
                3 回答
                            慕哥6287543
                            
                                
                            
                        
                        
                                                
                    TA贡献1831条经验 获得超10个赞
<?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::__construct
sudo aptitude install php5-xdebug
sudo aptitude install php5-dev
                            慕姐4208626
                            
                                
                            
                        
                        
                                                
                    TA贡献1852条经验 获得超7个赞
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;
    }- 3 回答
 - 0 关注
 - 638 浏览
 
添加回答
举报
0/150
	提交
		取消
	