2011-01-26 6 views
0

사용자 오류 처리기를 만들었으므로 비트 연산자를 올바르게 사용하고 싶습니다. 여기 비트 연산자와 오류 수준 (PHP)

// set user error handler 
set_error_handler('user_error_handler', E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE); 

오류 핸들러 자체이다 :

여기
// user error logging level (change for production) 
define('LEV_USER_ERROR_LOG_LEVEL', E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE); 

// user error display level (change for production) 
define('LEV_USER_ERROR_DISPLAY_LEVEL', E_USER_ERROR); 

내가 사용자 오류 처리기를 설정하는 방법입니다 : 여기

어떤 방식으로 처리 될 오류를 설정하는 내 구성 설정입니다 :

// user error handler 
    public static function user_error_handler($error_level, $message, $file_name, $line_number) { 
     if (LEV_USER_ERROR_LOG_LEVEL | LEV_USER_ERROR_DISPLAY_LEVEL == 0) return true; 
     switch ($error_level) { 
      case E_USER_ERROR: 
       if (LEV_USER_ERROR_LOG_LEVEL & E_USER_ERROR) { 
        error_log('[' . date('Y-m-d h:i:s') . '] User Error: "' . $message . '", File: "'.$file_name.'", Line: '.$line_number.', Request: "' . $_SERVER['ORIG_PATH_INFO'] . "\"\n", 3, 'application/logs/user_error_log.txt'); 
       } 
       if (LEV_USER_ERROR_DISPLAY_LEVEL & E_USER_ERROR) { 
        echo '[' . date('Y-m-d h:i:s') . '] User Level Error: "' . $message . '", File: "'.$file_name.'", Line: '.$line_number.'<br />'; 
       } 
       die; 
       break; 
      case E_USER_WARNING: 
       if (LEV_USER_ERROR_LOG_LEVEL & E_USER_WARNING) { 
        error_log('[' . date('Y-m-d h:i:s') . '] User Warning: "' . $message . '", File: "'.$file_name.'", Line: '.$line_number.', Request: "' . $_SERVER['ORIG_PATH_INFO'] . "\"\n", 3, 'application/logs/user_error_log.txt'); 
       } 
       if (LEV_USER_ERROR_DISPLAY_LEVEL & E_USER_WARNING) { 
        echo '[' . date('Y-m-d h:i:s') . '] User Level Warning: "' . $message . '", File: "'.$file_name.'", Line: '.$line_number.'<br />'; 
       } 
       break; 
      case E_USER_NOTICE: 
       if (LEV_USER_ERROR_LOG_LEVEL & E_USER_NOTICE) { 
        error_log('[' . date('Y-m-d h:i:s') . '] User Notice: "' . $message . '", File: "'.$file_name.'", Line: '.$line_number.', Request: "' . $_SERVER['ORIG_PATH_INFO'] . "\"\n", 3, 'application/logs/user_error_log.txt'); 
       } 
       if (LEV_USER_ERROR_DISPLAY_LEVEL & E_USER_NOTICE) { 
        echo '[' . date('Y-m-d h:i:s') . '] User Level Notice: "' . $message . '", File: "'.$file_name.'", Line: '.$line_number.'<br />'; 
       } 
       break; 
      default: 
       // call PHP internal error handler 
       return false; 
     } 
     // do not call PHP internal error handler 
     return true; 
    } 

질문 :

  1. 내 처리기 설정에서 사용되는 비트 OR 연산자를 사용하면 세 가지 오류 중 하나가 발생할 때만 오류 처리기가 호출됩니다.
  2. 오류 처리기의 첫 번째 줄에 사용 된 비트 OR 연산자는 구성 설정이 모두 0으로 설정된 경우에만 함수가 종료되도록 설정합니다. 라인

    if (LEV_USER_ERROR_LOG_LEVEL | LEV_USER_ERROR_DISPLAY_LEVEL == 0) return true; 
    

    비교가 비트 연산자보다 강에서

답변

1

, 그래서 당신은 괄호가 필요합니다 : 당신이 설명하는대로

if ((LEV_USER_ERROR_LOG_LEVEL | LEV_USER_ERROR_DISPLAY_LEVEL) == 0) return true; 

그런 다음 코드가 작동합니다.