php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #15523 Line Number
Submitted: 2002-02-12 10:24 UTC Modified: 2003-01-18 14:43 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: blanke at ddd dot de Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.1.1 OS: Linux
Private report: No CVE-ID: None
 [2002-02-12 10:24 UTC] blanke at ddd dot de
Hi there !

I think it would be great if it would be possible to find out from which line of a script a function has been called.
example

1 function blah()
2 {
3    echo("Function blah has been called from line 6");
4 }
5
6 blah();


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-12 10:39 UTC] mj@php.net
The constant __LINE__ contains the current line number.
 [2002-02-12 10:40 UTC] jan@php.net
in fact it is bogus ;)
 [2002-02-12 10:45 UTC] blanke at ddd dot de
Hi there!

That's correct, that __LINE__ contains the !current! Line-Number. But I
what to know from which line a function has been called.

> >
> > 1 function blah()
> > 2 {
> > 3    echo("Function blah has been called from line 6");
> > 4 }
> > 5
> > 6 blah();
> >

In line 3, i don't want to know the CURRENT line Number. I'd like to
know the Line-Number from which that Function has been called.


mfg, Nico Blanke.
 [2002-02-12 10:47 UTC] jan@php.net
what about 
function foo($line)
{
  echo 'the function was called in line: '.$line
}
foo(__LINE__);
?
 [2002-02-12 10:51 UTC] blanke at ddd dot de
That would work of course. 
The problem is, that our company has written a set of php functions, which are used by one of our clients.

The functions include some error-handling like wrong arguments or something like that, and I'd like to tell them the linenumber.

I think its not very useful that they have to put __LINE__ into every function call :)
 [2002-02-12 10:53 UTC] jan@php.net
reopening, this is a serious request ;)
 [2002-06-08 10:44 UTC] bigredlinux at yahoo dot com
What would be nice is if line() and file() were functions and they returned an array of line numbers and files...Hence, for each level of depth you proceed, it would array_push the line and file and then when you exited it would pop them.  That way, you could get the whole hierarchy, and without and punishment.  I realize that php is going towards stack tracing, but this would be HUGE.  PEAR_Error would actually be helpful in cases that used this functionality.
 [2003-01-18 14:43 UTC] moriyoshi@php.net
Try debug_backtrace().

<?php
function test() {
    var_dump(debug_backtrace());
}

test();
?>

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 27 12:00:02 2025 UTC