function debug() 

if (!defined('DEBUG')) 

return; 


$args = func_get_args(); 
$msg = $args[0]; 
array_shift($args); 

$extra = implode(' ', $args); 

printf("[debug] $msg [extra] $extran"); 


function debugn($times) 

static $n = 0; 

if ($n < $times) 

$n++; 

$args = func_get_args(); 
array_shift($args); 
$call = 'debug('; 
foreach($args as $arg) 

if (gettype($arg) == 'string') 
$arg = ""$arg""; 
$call .= $arg.','; 

$call = substr($call, 0, -1).');'; 
eval($call); 


return; 
}
 

debug 会显示debug信息, 当DEBUG被定义的时候. 例如: 
(debug will show debug information when DEBUG is defined. For example 

define('DEBUG', true); 
debug('the following sql will be executed', 'SELECT * FROM some_table'); 



结果(Result): 
[debug] the following sql will be executed [extra] SELECT * FROM some_table 

debugn用在循环中, 类似debug. 
(debugn used in loops, like debug.) 

define('DEBUG', true);  

for($i = 0; $i < 100; $i++)  
{  
  debugn(7, 'the i value currently is '.$i);  
  if ($i == 99) print "task overn";  
}  
[debug] the i value currently is 0 [extra]  
[debug] the i value currently is 1 [extra]  
[debug] the i value currently is 2 [extra]  
[debug] the i value currently is 3 [extra]  
[debug] the i value currently is 4 [extra]  
[debug] the i value currently is 5 [extra]  
[debug] the i value currently is 6 [extra]  
task over