2014-03-28 3 views
1

NOTICE 오류가 발생한 실제 코드 줄 (번호, 코드 줄이 아님)을 잡고 싶습니다. 이것을 달성 할 방법이 있습니까? 나는 현재 실행중인 스크립트에서 특정 줄 #에 코드를 반환하는 함수를 찾지 못하는 것 같습니다. PHP 스크립트를 가정PHP - 오류를 던진 코드를 잡아

+1

[ErrorException을 throw하도록 오류 처리기를 설정] (http://php.net/manual/class.errorexception.php#errorexception.example.error-handler) 그런 다음 [stack trace] (http://php.net/manual/exception.gettrace.php)? – Phil

답변

1

현재 파일을 읽을 수있는 권한을 가지고, 당신은이 작업을 수행 할 수 있습니다

<?php 

echo $b; // Undefined variable 

$errors = error_get_last(); 

$errorMessage = $errors['message'];  
$pathToScript = $errors['file']; 
$line = $errors['line']; 

$arrayOfLines = file(__FILE__); 

echo "The error message was: '$errorMessage occured in $pathToScript'"; 
echo "The line of code that caused the error is: \n"; 

highlight_string($arrayOfLines[$line-1]); 

출력 :

오류 메시지가 있었다 : '정의되지 않은 변수 :에 발생 B/경로를 /to/script.php '

오류가 발생한 코드 라인은 : echo $b;

,
관련 문제