user_error 함수

함수 user_error (trigger_error로도 알려짐)는 사용자 정의 오류 메시지를 생성합니다. 첫 번째 매개변수는 메시지 문자열을, 두 번째 매개변수는 오류 유형(E_USER_NOTICE, E_USER_WARNING 또는 E_USER_ERROR)을 받습니다.

구문

phpuser_error(message, error_type);

예시

간단한 알림(E_USER_NOTICE) 생성하기:

php<?php
  user_error('This is a notice', E_USER_NOTICE);
?>

코드 실행 결과:

phpNotice: This is a notice

예시

경고(E_USER_WARNING) 생성하기:

php<?php
  user_error('Warning: invalid value', E_USER_WARNING);
?>

코드 실행 결과:

phpWarning: Warning: invalid value

예시

치명적 오류(E_USER_ERROR) 생성하기:

php<?php
  user_error('Critical error occurred', E_USER_ERROR);
  echo 'This line will not execute';
?>

코드 실행 결과:

phpFatal error: Critical error occurred