dongzhang6677 2013-08-03 20:52
浏览 34

获取函数被调用的行? [重复]

This question already has an answer here:

I've looked this up and I know that the answer probably involves the use of debug_backtrace(), but I am struggling on how to use it or exactly what it does.

Basically, if this was index.php:

<?php
//some code
//some more code

require "functions.php";

print_line();

//some code

print_line();
?>

and functions.php was:

<?php
function print_line(){
    $line="[line that this function was called at]";
    print "This function was called from line $line of index.php<br />";
}
?>

What would be the correct way of setting $line so that the output would be:

This function was called from line 7 of index.php
This function was called from line 11 of index.php
</div>
  • 写回答

2条回答 默认 最新

  • dongmopu6734 2013-08-03 20:54
    关注

    You can use the code below to get the current line, just pass it in as a parameter to your print_line() function

    print_line(__line__);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作