framework/base/CErrorHandler.php
protected function renderSourceCode($file,$errorLine,$maxLines)
	{
		$errorLine--;	// adjust line number to 0-based from 1-based
		if($errorLine<0 || ($lines=@file($file))===false || ($lineCount=count($lines))<=$errorLine)
			return '';

		$halfLines=(int)($maxLines/2);
		$beginLine=$errorLine-$halfLines>0 ? $errorLine-$halfLines:0;
		$endLine=$errorLine+$halfLines<$lineCount?$errorLine+$halfLines:$lineCount-1;
		$lineNumberWidth=strlen($endLine+1);

		$output='';
		for($i=$beginLine;$i<=$endLine;++$i)
		{
			$isErrorLine = $i===$errorLine;
			$code=sprintf("<span class=\"ln".($isErrorLine?' error-ln':'')."\">%0{$lineNumberWidth}d</span> %s",$i+1,CHtml::encode(str_replace("\t",'    ',$lines[$i])));
			if(!$isErrorLine)
				$output.=$code;
			else
				$output.='<span class="error">'.$code.'</span>';
		}
		return '<div class="code"><pre>'.$output.'</pre></div>';
	}
protected function renderSourceCode($file,$errorLine,$maxLines)
	{
		$errorLine--;	// adjust line number to 0-based from 1-based
		if($errorLine<0 || ($lines=@file($file))===false || ($lineCount=count($lines))<=$errorLine)
			return '';

		$halfLines=(int)($maxLines/2);
		$beginLine=$errorLine-$halfLines>0 ? $errorLine-$halfLines:0;
		$endLine=$errorLine+$halfLines<$lineCount?$errorLine+$halfLines:$lineCount-1;
		$lineNumberWidth=strlen($endLine+1);

		$output='';
		for($i=$beginLine;$i<=$endLine;++$i)
		{
			$isErrorLine = $i===$errorLine;
			$code=sprintf("<span class=\"ln".($isErrorLine?' error-ln':'')."\">%0{$lineNumberWidth}d</span> %s",$i+1,CHtml::encode(str_replace("\t",'    ',$lines[$i])));
			if(!$isErrorLine)
				$output.=$code;
			else
				$output.='<span class="error">'.$code.'</span>';
		}
		return '<div class="code"><pre>'.$output.'</pre></div>';
	}
protected function renderSourceCode ( $ file , $ errorLine , $ maxLines ) { $ errorLine -- ; // adjust line number to 0-based from 1-based if ( $ errorLine < 0 || ( $ lines = @ file ( $ file ) ) === false || ( $ lineCount = count ( $ lines ) ) <= $ errorLine ) return '' ; $ halfLines = ( int ) ( $ maxLines / 2 ) ; $ beginLine = $ errorLine - $ halfLines > 0 ? $ errorLine - $ halfLines : 0 ; $ endLine = $ errorLine + $ halfLines < $ lineCount ? $ errorLine + $ halfLines : $ lineCount - 1 ; $ lineNumberWidth = strlen ( $ endLine + 1 ) ; $ output = '' ; for ( $ i = $ beginLine ; $ i <= $ endLine ; ++ $ i ) { $ isErrorLine = $ i === $ errorLine ; $ code = sprintf ( "<span class=\"ln" . ( $ isErrorLine ? ' error-ln' : '' ) . "\">%0{$lineNumberWidth}d</span> %s" , $ i + 1 , CHtml :: encode ( str_replace ( "\t" , '    ' , $ lines [ $ i ] ) ) ) ; if ( ! $ isErrorLine ) $ output .= $ code ; else $ output .= '<span class="error">' . $ code . '</span>' ; } return '<div class="code"><pre>' . $ output . '</pre></div>' ; }
Renders the source code around the error line.
@param string $file source file path
@param integer $errorLine the error line number
@param integer $maxLines maximum number of lines to display
@return string the rendering result
Renders the source code around the error line .