|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53882 Exception::getLine method returns line where Exception created not Thrown
Submitted: 2011-01-30 01:01 UTC Modified: 2011-02-10 16:03 UTC
From: james at jarofgreen dot co dot uk Assigned: vrana
Status: Closed Package: *General Issues
PHP Version: Irrelevant OS: Ubuntu
Private report: No CVE-ID:
 [2011-01-30 01:01 UTC] james at jarofgreen dot co dot uk
------------ says "Returns line number where the exception was thrown."

However it seems to be returning the line number the Exception was created, not thrown.

A) This is a code bug.
B) This is a documentation bug.

I am using PHP Version 5.3.3-1ubuntu9.3

I found which seems to suggest this is how the code is meant to work. In this case the documentation is wrong.

Test script:
Change the sample code from that page slightly to:

try {
    $e = new Exception("Some error message");
    throw $e;
} catch(Exception $e) {
    echo "The exception was thrown on line: " . $e->getLine();

Expected result:
The exception was thrown on line: 4

Because line 4 is the line where the Exception was Thrown.

Actual result:
The exception was thrown on line: 3

That's the line where the Exception was created. This contradicts the documentation.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-10 16:03 UTC]
Automatic comment from SVN on behalf of vrana
Log: Exception informs about the point of creation not throwing (doc bug #53882)
 [2011-02-10 16:03 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: vrana
 [2011-02-10 16:03 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Valid also for getFile().
 [2011-02-10 23:25 UTC] james at jarofgreen dot co dot uk
> Valid also for getFile().

Yeah, I assumed it'd apply to a couple of functions on the Exception class but this was the easiest to prove so I thought I'd do this first and see if it got picked up.

PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 20:01:34 2015 UTC