2006-01-12 00:47:36 trace function
( php )
  1  <?php
2 function trace($description, $information=false, $active=true){
3 if ($active && TRACE){
4 $time = date('i:s');
5 if($information)
6 $displayinfo = $information;
7 else
8 $displayinfo = '{$description}';
9 echo '<hr/>'.$time.' — <b>'.$description.':</b><br/><pre>'. $displayinfo .'</pre><hr/>';
10 }
11 }
12 ?>
  • Jeff (Thu, January 12th, 2006, 12:56am UTC)
    Not relevant, but an optional way to write that if:
    ( php )
      1  $displayInfo = $information ? $information : '{$description}';

    not that you didn't realize that.

  • jjb (Thu, January 12th, 2006, 1:02am UTC)
    yeah that's how i initially had it, but when it wasn't working i did it the "traditional" way to make sure i wasn't missing anything.

    here's what i got now

    ( php )
      1  function trace($description, $information=false, $active=true){
    2 //TODO: add filename and linenumber info
    3 if ($active && TRACE){
    4 $time = date('i:s');
    5 if($information)
    6 $displayinfo = $information;
    7 else
    8 $displayinfo = '{$description}';
    9 echo '<hr/>'.$time.' — <b>'.$description.':</b><br/><pre>'.$displayinfo .'</pre><hr/>';
    10 }
    11 }


    The new question is, if $description is a string, how do i get it to evaluate. hmm actually that might be impossible since the variable would be outside of the scope.

  • jjb (Thu, January 12th, 2006, 1:02am UTC)
    WHOOPS. HERE is the latest version

    ( php )
      1  function trace($description, $information=false, $active=true){
    2 //TODO: add filename and linenumber info
    3 if ($active && TRACE){
    4 $time = date('i:s');
    5 $information !== false ? $information : '{$description}';
    6 echo '<hr/>'.$time.' — <b>'.$description.':</b><br/><pre>'. $displayinfo .'</pre><hr/>';
    7 }
    8 }

  • Jeff (Thu, January 12th, 2006, 1:04am UTC)
    when stoners code…

  • Jeff (Thu, January 12th, 2006, 1:06am UTC)
    Explain what you want with $description

Leave a comment