라이브러리
[PHP] Error::getFile - 오류가 발생한 파일을 가져옵니다.
PHP 에서 Error::getFile() 함수
PHP 에서 `Error::getFile()` 함수는 에러가 발생한 파일의 경로를 반환합니다. 이 함수는 PHP 7.2 이상에서 사용할 수 있습니다.
# 사용법
`Error::getFile()` 함수는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
error_reporting(E_ALL);
ini_set('display_errors', 1);
try {
// 에러가 발생할 코드
$x = 1 / 0;
} catch (Error $e) {
echo "에러 메시지: " . $e->getMessage() . "
";
echo "에러 파일: " . $e->getFile() . "
";
echo "에러 줄번호: " . $e->getLine() . "
";
}
# 예제
다음 예제는 `Error::getFile()` 함수를 사용하여 에러가 발생한 파일의 경로를 반환하는 방법을 보여줍니다.
#hostingforum.kr
php
// test.php
<?php
function divide($a, $b) {
return $a / $b;
}
$result = divide(10, 0);
echo $result;
#hostingforum.kr
php
// main.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
try {
require_once 'test.php';
} catch (Error $e) {
echo "에러 메시지: " . $e->getMessage() . "
";
echo "에러 파일: " . $e->getFile() . "
";
echo "에러 줄번호: " . $e->getLine() . "
";
}
`main.php` 파일을 실행하면 다음과 같은 출력이 나타납니다.
#hostingforum.kr
에러 메시지: Division by zero
에러 파일: /path/to/test.php
에러 줄번호: 6
위 예제에서 `Error::getFile()` 함수는 `test.php` 파일의 경로를 반환합니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.