Files
2nd/10_Wiki/Dev/Topic_PHP/PHP_Error_Handling.md
T
Antigravity Agent 1cfd3bbb56 docs(10_Wiki): 위키 구조 정리 — 언어 튜토리얼 카테고리 폴더 제거 + 신규 자산 동기화
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고,
Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
2026-07-05 00:10:59 +09:00

4.3 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
php-error-handling PHP Error Handling Programming_Language draft conceptual
set_error_handler
trigger_error
PHP 에러 처리
B 0.9 2026-07-04 2026-07-04
php
programming
w3schools
error-handling
https://www.w3schools.com/php/php_error_handling.asp

PHP Error Handling

🎯 한 줄 통찰 (One-line insight)

set_error_handler() REPLACES PHP's built-in error handler for the rest of the script — meaning ANY error (even something as ordinary as referencing an undefined variable) routes through your custom function instead of the default warning, which is why the custom handler in the source catches echo($test); (an undefined-variable notice) just as easily as a triggered error. [S1]

🧠 핵심 개념 (Core concepts)

  • die() — simplest error handling: stop the script and print a message (e.g., after checking file_exists()). [S1]
  • Custom error handler function — accepts (error_level, error_message, [error_file, error_line, error_context]) — minimum 2, up to 5 parameters. [S1]
  • Error report levelsE_WARNING (2, non-fatal), E_NOTICE (8), E_USER_ERROR (256, fatal user-generated), E_USER_WARNING (512), E_USER_NOTICE (1024), E_RECOVERABLE_ERROR (4096), E_ALL (8191). [S1]
  • set_error_handler("functionName", errorLevel) — installs a custom handler, optionally scoped to a specific error level. [S1]
  • trigger_error($message, $level) — manually raises a custom error, useful for flagging invalid user input. [S1]
  • error_log() — sends error logs to a file, the server's system, or (with the mail-mode parameter) directly to an email address. [S1]

📖 세부 내용 (Details)

  • Basic die(): if(!file_exists("welcome.txt")) { die("File not found"); } else { $file=fopen("welcome.txt","r"); }. [S1]
  • Custom handler function: function customError($errno, $errstr) { echo "<b>Error:</b> [$errno] $errstr<br>"; echo "Ending Script"; die(); }. [S1]
  • Registering the handler: set_error_handler("customError");. [S1]
  • Triggering a custom error: if ($test>=1) { trigger_error("Value must be 1 or below", E_USER_WARNING); }. [S1]
  • Scoped handler (only E_USER_WARNING): set_error_handler("customError", E_USER_WARNING);. [S1]
  • Emailing an error log: error_log("Error: [$errno] $errstr", 1, "someone@example.com", "From: webmaster@example.com");. [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

  • 커스텀 핸들러가 모든 에러를 가로챔: 별도 에러 레벨을 지정하지 않으면 정의되지 않은 변수 참조 같은 사소한 것까지 모두 커스텀 핸들러로 라우팅된다는 점이 실험 예제로 검증됨. [S1]

🛠️ 적용 사례 (Applied in summary)

현재 발견된 실제 적용 사례가 없습니다 — 특정 에러 발생 시 웹마스터에게 이메일 알림을 보내는 것이 실전 모니터링의 대표 사례다. [S1]

💻 코드 패턴 (Code patterns)

Custom error handler scoped to a specific error level (PHP):

function customError($errno, $errstr) {
    echo "<b>Error:</b> [$errno] $errstr<br>";
    echo "Ending Script";
    die();
}
set_error_handler("customError", E_USER_WARNING);
$test = 2;
if ($test >= 1) {
    trigger_error("Value must be 1 or below", E_USER_WARNING);
}

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.90
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "PHP Error Handling" page (Astra wiki-curation, P-Reinforce v3.1 format).