Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199807

Re: [PHP3] #ifdef and #endif From: Richard Lynch (lynch <email protected>)
Date: 07/22/98

At 8:27 AM 7/22/98, Walter Dougoveto wrote:
>I was just wondering if there was anything like the #ifdef and #endif in C
>that you could use with PHP for debugging? If not, what would you suggest?
> I have been adding statements for debugging and then taking them out but
>it is not very efficient. It would be good to have a way to turn them on
>or off using one statement.

In larger packages, you may wish to consider using something like this:

$DEBUG_SQL = 1;
$DEBUG_LOGIC = 1;
$DEBUG_OUTPUT = 1;

if ($DEBUG_SQL){
  echo("$query<BR>\n");
}

if (...somecomplextest...){
  if ($DEBUG_LOGIC){
    echo("...somecomplextestdescription... TRUE.<BR>\n");
  }
}
else{
  if ($DEBUG_LOGIC){
    echo("...somecomplextestdescription... FALSE.<BR>\n");
  }
}

The point being that I generally find that if I need a debug output once,
I'll need it again later (when I find another bug), but I don't want to
turn them all on at once.

So if I think my SQL is returning or, <deity>-forbid, updating and
inserting:-( the wrong data, I can debug my SQL without seeing reams of
output from the logic debugging I was doing last week, but don't need right
now.

I classify my debugging statements into:
  SQL the actual queries and their return values
  LOGIC the flow of the PHP if/while/for et al
  OUTPUT nested tables and forms and such
          [Be careful to get the debug output into <TR><TD> tags for tables...]

I sometimes add another special flag for a particularly nasty or
intermittent bug and leave it on long-term.

Whew. Hope somebody whose never tried this finds this idea useful.

PS As far as performance of the if ($DEBUG) goes... I've always figured
that except for the tightest loops, it just doesn't matter compared to the
slowness of the net. But I do comment them out of really tight loops,
since they usually are fairly reliable, once you get it right... But leave
the code in a comment just in case.

--
--
-- "TANSTAAFL" Rich lynch <email protected>

-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3