Posted by Jochem Maas on 07/30/05 23:20
Andy Pieters wrote:
> Hi all
>
> We develop our software with built-in debug handlers that are very talkative.
> Each class registers itself to a central debug handler. When a conditional
> define NODEBUG is set, that debughandler just does a return null but
> obviously it takes time to perform that call.
>
> We are thinking of doing a search/replace on the source to replace all
> $this->debug('...'); with a ; because if I would replace it with a # it would
> generate errors in cases like this:
>
> if(conditions ....)
> $this->debug('something...');
asumming replacing the call with ; is valid everywhere it's going to a heck of
a lot faster than calling _any_ function.
>
> So here is the question:
>
> Are there any reasons against doing this kind of replace, or is anyone aware
> of a better solution?
1. use a debugger rather than writing lots of code that logs tons of 'cr*p'?
2. always use braces? so that you can do:
if(conditions ....) {
# $this->debug('something...');
}
3. may put special comment markers in your code that allow you
to filter the files when you 'publish' them into a production env.
/*START_DEBUG_BLOCK*/
if(conditions ....)
$this->debug('something...');
/*END_DEBUG_BLOCK*/
i.e strip the blocks completely:
$newFile = preg_replace( '#/\*START_DEBUG_BLOCK\*/.*/\*END_DEBUG_BLOCK\*/#',
'',
file_get_contents( $yourPhpFile ) );
>
> With kind regards
>
>
> Andy
>
[Back to original message]
|