1 回答
TA贡献1818条经验 获得超7个赞
debug_backtrace的返回值应该返回第二个条目(索引 1)中的调用函数,例如:
<?php
function current_user_can()
{
$backtrace = debug_backtrace(false, 2);
// ToDo: Check if $backtrace[1] (and especially the class-key of that) actually exist...
// It should always (although the class key might not if this function isn't called from within a class), since this function is being called
// but it's still a good habbit to check array keys before accessing the array
$callerClass = $backtrace[1]["class"];
$callerMethod = $backtrace[1]["function"];
// ToDo: implementation of check, in this example $callerClass would be "User" and $callerMethod would be "list_user_data"
return true;
}
class User {
public function list_user_data() {
if (current_user_can())
{
}
}
}
$user = new User();
$user->list_user_data();
- 1 回答
- 0 关注
- 130 浏览
添加回答
举报