Determine the line number that called a function.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Zim

    Determine the line number that called a function.

    Greetings,

    I have an all purpose variable dumper that uses Var_Dump to show me
    data structures.

    I have an application wide function that I simply call to dump a
    structure:

    vardump($var);

    function vardump ($vars, $details = null) {

    if ($vars == 'dump') {
    if (isset($GLOBALS['vardump']) ) {

    Var_Dump::displ ay($GLOBALS['vardump'],'GLOBALS',VAR_ DUMP_DISPLAY_MO DE_HTML_TABLE);
    }
    }
    if ( isset($details) ) {
    $GLOBALS['vardump'][$details][] = $vars;
    } else {
    $GLOBALS['vardump'][] = $vars;
    }

    }
    The function can also accept a second argument that lets dumps
    information about who/what/where the variable is being dumped from.

    Now, sometimes I'm dumping alot so I would like to know where exactly
    the dump came from, like this:

    vardump($rows, basename(__FILE __) .' <br> '. __LINE__ );

    Now, I'd like to keep the vardump() call as clean as possible. Is there
    anyway for the function vardump to know the __FILE__ and __LINE__
    without being told in an argument?

    Many thanks!

  • Garp

    #2
    Re: Determine the line number that called a function.


    "Zim" <27b67k602@snea kemail.com> wrote in message
    news:cc1jck$kua @odak26.prod.go ogle.com...[color=blue]
    > Greetings,
    >[/color]
    <snip>[color=blue]
    > Now, sometimes I'm dumping alot so I would like to know where exactly
    > the dump came from, like this:
    >
    > vardump($rows, basename(__FILE __) .' <br> '. __LINE__ );
    >
    > Now, I'd like to keep the vardump() call as clean as possible. Is there
    > anyway for the function vardump to know the __FILE__ and __LINE__
    > without being told in an argument?[/color]

    You, Sir, seek a stack trace. Such a thing does not exist. Google records
    the following from 2002 in php.general:

    "There is no native PHP function for getting a stack trace. This has been
    discussed many times on the PHP-DEV mailing list. It has always been
    discarded due to an unacceptable overhead that would be introduced into the
    parsing process."

    Sorry it's not better news.

    Garp


    Comment

    • Phil Roberts

      #3
      Re: Determine the line number that called a function.

      "Garp" <garp7@no7.blue yonder.co.uk> emerged reluctantly from the
      curtain and staggered drunkenly up to the mic. In a cracked and
      slurred voice he muttered:
      [color=blue]
      > You, Sir, seek a stack trace. Such a thing does not exist.
      > Google records the following from 2002 in php.general:
      >[/color]

      Oh rrrreeeeallly?

      *COUGH* http://uk.php.net/debug_backtrace *COUGH*

      --
      Phil Roberts | Without me its just aweso. | http://www.flatnet.net/

      "Mankind differs from the animals only by a little,
      and most people throw that away."
      - Confucious

      Comment

      • Garp

        #4
        Re: Determine the line number that called a function.


        "Phil Roberts" <phil.roberts@g ooglemail.com> wrote in message
        news:Xns9519C46 0FFC20philrober ts@216.196.97.1 32...[color=blue]
        > "Garp" <garp7@no7.blue yonder.co.uk> emerged reluctantly from the
        > curtain and staggered drunkenly up to the mic. In a cracked and
        > slurred voice he muttered:
        >[color=green]
        > > You, Sir, seek a stack trace. Such a thing does not exist.
        > > Google records the following from 2002 in php.general:
        > >[/color]
        >
        > Oh rrrreeeeallly?
        >
        > *COUGH* http://uk.php.net/debug_backtrace *COUGH*[/color]

        God, when did that appear! >hugz< Ah, 4.3.0........ I predate that. Yay!

        Garp




        Comment

        Working...