Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6118087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:23:43+00:00 2026-05-23T15:23:43+00:00

I’m finding that sometimes debug_backtrace() is not including the line number for a call.

  • 0

I’m finding that sometimes debug_backtrace() is not including the line number for a call. Is there some reason why this is and any way to correct for it?

Thanks in advance.

P.S. And yes, the calls that it is omit line numbers for are my own code, not internal PHP code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:23:44+00:00Added an answer on May 23, 2026 at 3:23 pm

    Consider following code:

    <?
    class BtTest
    {
      public function getTheItem()
      {
        var_dump( debug_backtrace( false ) );
        $bt = debug_backtrace( false );
        return $bt[1];
      }
    
      public function __call( $methodName, $methodArgs )
      {
        return $this->getTheItem();
      }
    }
    
    $o = new BtTest();
    $bti = $o->test();
    
    assert( 'array_key_exists("function", $bti)' );
    assert( 'array_key_exists("line", $bti)' );
    assert( 'array_key_exists("file", $bti)' );
    

    The execution of above example generates following output:

    array(3) {
      [0]=>
      array(6) {
        ["file"]=>
        string(53) "/somewhere/in/the/filesystem/tests/bt-test-so.php"
        ["line"]=>
        int(13)
        ["function"]=>
        string(10) "getTheItem"
        ["class"]=>
        string(6) "BtTest"
        ["type"]=>
        string(2) "->"
        ["args"]=>
        array(0) {
        }
      }
      [1]=>
      array(4) {
        ["function"]=>
        string(6) "__call"
        ["class"]=>
        string(6) "BtTest"
        ["type"]=>
        string(2) "->"
        ["args"]=>
        array(2) {
          [0]=>
          &string(4) "test"
          [1]=>
          &array(0) {
          }
        }
      }
      [2]=>
      array(6) {
        ["file"]=>
        string(53) "/somewhere/in/the/filesystem/tests/bt-test-so.php"
        ["line"]=>
        int(18)
        ["function"]=>
        string(4) "test"
        ["class"]=>
        string(6) "BtTest"
        ["type"]=>
        string(2) "->"
        ["args"]=>
        array(0) {
        }
      }
    }
    PHP Warning:  assert(): Assertion "array_key_exists("line", $bti)" failed in /somewhere/in/the/filesystem/tests/bt-test-so.php on line 21
    PHP Warning:  assert(): Assertion "array_key_exists("file", $bti)" failed in /somewhere/in/the/filesystem/tests/bt-test-so.php on line 22
    

    The first backtrace item (index 0) says indirectly (through the line and file items) that the getTheItem method was called from the __call method.

    The second backtrace item (index 1) says that the __call method was called from somewhere (missing line and file items).

    The third backtrace item (index 2) says that the test method was called from the global scope of the script.

    The place of the __call method call is probably in some method resolution code somewhere in the php interpreter code. There are two possibilities of fixing it. Either the second item should refer interpreter’s source code file and line or the second and the third backtrace items should be merged into one. I personally would prefer the second solution as the interpreter’s internals are not interesting for me (this is how they seem to do it in python’s traceback), however I understand that sometimes the first solution provides more explicit trace (especially when it’s a callback which is called from the internals).

    So or so, it seems that the developer(s) responsible for (or at least maintaining) the code of the debug_backtrace function doesn’t perceive it as a bug or maybe has no easy way to fix it. It would be ok to fill the line and file items with some place holder values (e.g. <unknown-file> and 0 or even nulls) and emphasize it in the documentation. Unless someone will successfully convince them to do it, you just have to handle the special case in your code.

    I wrote above just to share my understanding of the strange behaviour of the function. If someone has a willingness to fight for a slightly better world, here are links to some related bug reports:

    • #39070 debug_backtrace output when call_user_func or error handler involved
    • #24214 debug_backtrace() fails to report __FILE__, __LINE__
    • #24405 debug_backtrace – missing info
    • #38047 “file” and “line” sometimes not set in backtrace from inside error handler
    • #44428 “file” and “line” missing in debug_backtrace() output

    The oldest report is from 2003, so you shouldn’t count on a fast fix 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.