Conditional compilation
That depends on where the conditional exists. In C you can place it
anywhere, including wihtin a tight loop. In PHP you end up having to
either take an overhead penalty or duplicate code to force the
conditional outside of a tight loop.
Contrast the following:
<?php
if( DEBUG === true )
{
for( $i = 0; $i < 1000000; $i++ )
{
// Do something common between DEBUG and !DEBUG modes.
// Do something dependent on debug mode.
}
}
else
{
for( $i = 0; $i < 1000000; $i++ )
{
// Do something common between DEBUG and !DEBUG modes. } }
?>
Versus:
<?php
for( $i = 0; $i < 1000000; $i++ )
{
// Do something common between DEBUG and !DEBUG modes.
if( DEBUG === true )
{
// Do something dependent on debug mode. } }
?>
Now depending on what "Do something common between DEBUG and !DEBUG
modes" does, it can be a real PITA to do code duplication to optimize
debug mode handling, but on the other hand, you really don't want to
check if DEBUG is enabled 1 million times.
If I recall though... a few years ago the answer to this question was
that there's no reason why you can't use the C pre-processor to
accomplish the same thing with PHP. The down side though is that then
you lose debugging information such as the real line number on which an
error occurs.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
|