SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    Not yet perfect mattalexx's Avatar
    Join Date
    Oct 2005
    Location
    Taos, NM, US
    Posts
    441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    __LINE__ of document calling function

    I have a function, d(), in include/functions.php:
    Code:
    function d($var, $name="") {
       if ($name) $_SESSION['debug_statements'][$name] = $var;
       else $_SESSION['debug_statements'][] = $var;
    }
    In include/footer.php, I spit all of the statements out:
    Code:
    foreach ($_SESSION['debug_statements'] as $key => $value) {
       print "
          <h4>$key:</h4>
          <div style='padding-left: 15px;'><pre>
          "; 
       print_r($value); 
       print "
          </pre></div>
          ";
    
       }
    My question is this: How do I display the correct __LINE__ and __FILE__ variables, to match where I have called d()?
    Matt Alexander
    Alexander Site Design

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    pass them when you call the function:
    PHP Code:
    d('myvariable'__LINE____FILE__'myvariable'

  3. #3
    Not yet perfect mattalexx's Avatar
    Join Date
    Oct 2005
    Location
    Taos, NM, US
    Posts
    441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was hoping to avoid the extra time it would take, but thanks for the answer, longneck.
    Matt Alexander
    Alexander Site Design

  4. #4
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could whip something up with debug_backtrace.

  5. #5
    Not yet perfect mattalexx's Avatar
    Join Date
    Oct 2005
    Location
    Taos, NM, US
    Posts
    441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's awesome, thanks!

    I wonder how debug_backtrace stayed below my radar for so long?
    Matt Alexander
    Alexander Site Design

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    btw, since were on the topic of debugging, take a look at xdebug
    http://pecl.php.net/package/Xdebug

    very powerful.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •