douzi8127 2011-12-04 14:57
浏览 23
已采纳

如何判断是否从输出缓冲回调中调用了该函数?

In a function, how can I find out if it's been called from an output buffering callback (not necessarily directly)?

function foo() {
    if (magic here ????)
        $log->write("foo:Callback") 
    else
        $log->write("foo:Normal")
}

function calls_foo() {
    ...stuff
    foo();
}

calls_foo() // should log foo:Normal

ob_start('calls_foo')

    ...stuff

// should log foo:Callback at the end of the script
  • 写回答

2条回答 默认 最新

  • dongluo1853 2011-12-04 15:08
    关注

    Check $debug = debug_backtrace(). If the debug array is 1 long then you get called from main which means this is an ob callback called at the end of the request. Then you can iterate the array and look at the 'function' key of each array for an ob flushing function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?