【发布时间】:2011-11-02 14:23:40
【问题描述】:
可能重复:
How to find out where a function is defined?
included php file to know it's file name?
我可以在 PHP 中获取函数声明开头的文件名和行号吗?
说,我有以下代码:
1. /**
2. * This function shows the foo bar.
3. */
4. function foo_bar($subject) {
5. echo "Foo bar:\n";
6. if ($subject == "none") {
7. trigger_error("Wrong argument given to 'foo_bar()' in ... on line ....", E_USER_WARNING);
8. }
9. ...
10. }
当我调用foo_bar("none") 时,函数必须抛出如下错误:
警告:第 4 行 /home/web/mcemperor 中的“foo_bar()”参数错误。
我可以检索函数声明开始的文件名和行号吗?
【问题讨论】:
-
@CodeCaster:不同意那个副本。这是关于知道函数定义所在的行和文件,而不是我们所在文件的文件名......
-
@ircmaxell 他想要一个函数本身(正在执行,所以设置了
__FILE__和__LINE__)来显示它的位置。