PHP 5中的調用者函數?是否有PHP函數來查找給定函數中調用方函數的名稱?
3 回答
人到中年有點甜
TA貢獻1895條經驗 獲得超7個贊
<?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
慕娘9325324
TA貢獻1783條經驗 獲得超4個贊
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 關注
- 401 瀏覽
添加回答
舉報
0/150
提交
取消
