2012-07-03 65 views
0

爲什麼包含錯誤回顯四次?set_error_handler包含錯誤的多個回聲

系統嘗試4次「打開流」嗎?

我所做的:

function errorHandler($errno, $errstr, $errfile, $errline) { 
    if ($errno == E_NOTICE) { 
     echo "<br/>".$errno."== E_NOTICE<br/>"; 
    } 
    if ($errno == E_USER_NOTICE) { 
     echo "<br/>".$errno."== E_USER_NOTICE<br/>"; 
    } 
    if ($errno == E_DEPRECATED) { 
     echo "<br/>".$errno."== E_DEPRECATED<br/>"; 
    } 
    if ($errno == E_USER_DEPRECATED) { 
     echo "<br/>".$errno."== E_USER_DEPRECATED<br/>"; 
    } 
    if ($errno == E_STRICT) { 
     echo "<br/>".$errno."== E_STRICT<br/>"; 
    } 
    if ($errno == E_WARNING) { 
     echo "<br/>".$errno."== E_WARNING<br/>"; 
    } 
    if ($errno == E_USER_WARNING) { 
     echo "<br/>".$errno."== E_USER_WARNING<br/>"; 
    } 
    if ($errno == E_ERROR) { 
     echo "<br/>".$errno."== E_ERROR<br/>"; 
    } 
    if ($errno == E_USER_ERROR) { 
     echo "<br/>".$errno."== E_USER_ERROR<br/>"; 
    } 
} 
set_error_handler("errorHandler"); 

結果:

2== E_WARNING 

2== E_WARNING 

2== E_WARNING 

2== E_WARNING 
+0

爲了增加獲得答案的機會,您應該添加一個對應於您正在使用的語言(php?)的標籤。 – assylias

+0

是的,它是PHP。 – SunnyOne

+0

有什麼錯誤? –

回答

1

沒有看到有關的其他信息到你的錯誤很難說。

Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include will finally check in the calling script's own directory and the current working directory before failing. The include construct will emit a warning if it cannot find a file; this is different behavior from require, which will emit a fatal error.

Docmumentation for include()

PHP considers each entry in the include path separately when looking for files to include. It will check the first path, and if it doesn't find it, check the next path, until it either locates the included file or returns with a warning or an error. You may modify or set your include path at runtime using set_include_path().

根據包含過程的PHP docs

在附註中,我對您提供的自定義功能errorHandler()進行了一些修改。

<?php 
function errorHandler($errno, $errstr, $errfile, $errline) { 
    $response; 

    switch ($errno){ 
     case E_NOTICE: 
      $reponse = 'E_NOTICE'; 
      break; 

     case E_USER_NOTICE: 
      $reponse = 'E_USER_NOTICE'; 
      break; 

     case E_DEPRECATED: 
      $reponse = 'E_DEPRECATED'; 
      break; 

     case E_USER_DEPRECATED: 
      $reponse = 'E_USER_DEPRECATED'; 
      break; 

     case E_STRICT: 
      $reponse = 'E_STRICT'; 
      break; 

     case E_WARNING: 
      $reponse = 'E_WARNING'; 
      break; 

     case E_USER_WARNING: 
      $reponse = 'E_USER_WARNING'; 
      break; 

     case E_ERROR: 
      $reponse = 'E_ERROR'; 
      break; 

     case E_USER_ERROR: 
      $reponse = 'E_USER_ERROR'; 
      break; 
    } 
    echo "<br />Errno: [$errno]; Type: [$reponse]<br />"; 
    echo "<br />Error on line [$errline] in file [$errfile]<br />"; 
    echo "<br />Error: ". $errstr . "<br />"; 
} 

set_error_handler("errorHandler"); 

?> 
+0

嗨RobB,經過一個短暫的夜晚,我正在考慮做你的建議,我試過你的代碼.......但我得到完全一樣的行爲:3次==>「Errno:[2];類型:[E_WARNING] 文件[703]中的錯誤[/home/.../public_html/index.php] 錯誤:include(afile.php)[0function.include0]:無法打開流:沒有文件或目錄「AND ONCE ===>」Errno:[2];類型:[E_WARNING]文件[703]中的錯誤[/home/.../public_html/index.php] 錯誤:include()[0function.include0]:打開'afile.php'失敗以包含(include_path ='。:/ usr/lib/php:/ usr/local/lib/php')「。讓我瘋狂......! – SunnyOne