모든 오류 및 경고 표시
이 질문에는 이미 답변이 있습니다.
- PHP 오류를 표시하려면 어떻게합니까? 답변 27 개
업데이트 2 :
이제 .php 파일에서 다음을 제거했습니다.
<?php error_reporting( E_ALL ); ?>
다음과 같이 php.ini에서 display_erros를 설정했습니다.
display_errors = 켜기
오류보고는 다음과 같이 설정됩니다 php.ini
.
error_reporting = E_ALL | E_STRICT
Apache를 다시 시작한 후에도 오류 / 경고가 나타나지 않습니다.
업데이트 1 :
다음 php.ini
에서 error_reporting을 변경했습니다 .
error_reporting = E_ALL 및 ~ E_DEPRECATED
에
error_reporting = E_ALL | E_STRICT
그 후 아파치를 다시 시작했습니다.
/etc/init.d/apache2 restart
그러나 페이지에는 여전히 어떤 종류의 오류 / 경고도 표시되지 않습니다.
원래 질문 :
다음 스크립트는 $ err가 if 문 안에 있기 때문에 경고를 생성합니다. 웹 브라우저의 PHP 페이지에이 경고가 표시되지 않는 이유는 무엇입니까?
경고를 보려면 Apache 로그를 살펴 봐야합니다. 또한 "삽입 위치"를 "삭제 위치"로 고의로 변경하면 PHP 페이지에 오류가 표시되지 않습니다. 실제 PHP 페이지에 오류가 표시되지 않는 이유는 무엇입니까?
<?php
error_reporting(E_ALL);
?>
<html>
<head>
<title></title>
<link rel="icon" type="image/png" href="favicon.ico">
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$err = array();
if (empty( $_POST['display_name']))
$err[] = "display name field is required";
if (empty( $_POST['email']))
$err[] = "email field is required";
if (empty( $_POST['password']))
$err[] = "password field is required";
if (!$err) {
try {
$DBH = new PDO("mysql:host=localhost;dbname=database1", "user", "pass");
$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$STH = $DBH->prepare("delete into table1 (display_name, email, password) values ( :display_name, :email, :password )");
$STH->bindParam(':display_name', $_POST['display_name'], PDO::PARAM_STR, 100);
$STH->bindParam(':email', $_POST['email'], PDO::PARAM_STR, 100);
$STH->bindParam(':password', $_POST['password'], PDO::PARAM_STR, 100);
$STH->execute();
$STH = $DBH->prepare("delete into table2 ( username, status, users_id ) values ( :username, :status, :users_id )");
$strStatus = 1;
$STH->bindParam(':username', $_POST['display_name'], PDO::PARAM_STR, 100);
$STH->bindParam(':status', $strStatus, PDO::PARAM_INT, 1);
$STH->bindParam(':users_id', $_POST['referer'], PDO::PARAM_INT, 1);
$STH->execute();
$DBH = null;
}
catch (PDOException $e) {
echo $e->getMessage();
}
header("Location: " . $_SERVER['PHP_SELF']);
exit;
}
else {
foreach ($_POST as $key => $val) {
$form[$key] = htmlspecialchars($val);
}
}
}
else {
$form['display_name'] = $form['email'] = $form['password'] = '';
}
?>
</head>
<body>
<?php foreach($err as $line) { ?>
<div style="error"><?php echo $line; ?></div>
<?php } ?>
<h1>Register</h1>
<form method="post">
Referers id:<br/>
<input type="text" name="referer" /><br/><br/>
Name:<br/>
<input type="text" name="display_name" value="<?php echo $form['display_name']; ?>" /><br/><br/>
Email:<br/>
<input type="text" name="email" value="<?php echo $form['email']; ?>" /><br/><br/>
Password:<br/>
<input type="text" name="password" value="<?php echo $form['password']; ?>" /><br/><br/>
<input type="submit" value="register" />
</form>
</body>
</html>
php.ini
또는 Apache 구성 파일 에서 표시 오류가 꺼질 수 있습니다 .
스크립트에서 켤 수 있습니다 :
error_reporting(E_ALL);
ini_set('display_errors', 1);
PHP 오류 로그에 동일한 메시지가 나타납니다.
php.ini 파일에서 직접 :
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This directive informs PHP of which errors, warnings and notices you would like
; it to take action for. The recommended way of setting values for this
; directive is through the use of the error level constants and bitwise
; operators. The error level constants are below here for convenience as well as
; some common settings and their meanings.
; By default, PHP is set to take action on all errors, notices and warnings EXCEPT
; those related to E_NOTICE and E_STRICT, which together cover best practices and
; recommended coding standards in PHP. For performance reasons, this is the
; recommend error reporting setting. Your production server shouldn't be wasting
; resources complaining about best practices and coding standards. That's what
; development servers and development settings are for.
; Note: The php.ini-development file has this setting as E_ALL. This
; means it pretty much reports everything which is exactly what you want during
; development and early testing.
;
; Error Level Constants:
; E_ALL - All errors and warnings (includes E_STRICT as of PHP 5.4.0)
; E_ERROR - fatal run-time errors
; E_RECOVERABLE_ERROR - almost fatal run-time errors
; E_WARNING - run-time warnings (non-fatal errors)
; E_PARSE - compile-time parse errors
; E_NOTICE - run-time notices (these are warnings which often result
; from a bug in your code, but it's possible that it was
; intentional (e.g., using an uninitialized variable and
; relying on the fact it is automatically initialized to an
; empty string)
; E_STRICT - run-time notices, enable to have PHP suggest changes
; to your code which will ensure the best interoperability
; and forward compatibility of your code
; E_CORE_ERROR - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's
; initial startup
; E_COMPILE_ERROR - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated notice message
; E_DEPRECATED - warn about code that will not work in future versions
; of PHP
; E_USER_DEPRECATED - user-generated deprecation warnings
;
; Common Values:
; E_ALL (Show all errors, warnings and notices including coding standards.)
; E_ALL & ~E_NOTICE (Show all errors, except for notices)
; E_ALL & ~E_NOTICE & ~E_STRICT (Show all errors, except for notices and coding standards warnings.)
; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors)
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
; http://php.net/error-reporting
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
순수한 개발을 위해 나는 다음을 수행합니다.
error_reporting = E_ALL ^ E_NOTICE ^ E_WARNING
또한 display_errors를 켜는 것을 잊지 마십시오
display_errors = On
그런 다음 Ubuntu에서 Apache 용 서버를 다시 시작하십시오.
sudo /etc/init.d/apache2 restart
아래 코드를 통해 모든 오류를 얻을 수있었습니다.
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
PHP 오류는 다음 방법 중 하나로 표시 될 수 있습니다.
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
상세 사항은:
이것들을 설정하십시오 php.ini
:
;display_startup_errors = On
display_startup_errors=off
display_errors =on
html_errors= on
PHP 페이지에서 오류보고에 적합한 필터를 사용하십시오.
error_reporting(E_ALL);
파일러는 요구 사항에 따라 만들 수 있습니다.
E_ALL
E_ALL | E_STRICT
ini_set('display_errors', 1);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
변경 로그
-
5.4.0 E_STRICT가 E_ALL의 일부가되었습니다
-
5.3.0 E_DEPRECATED 및 E_USER_DEPRECATED가 도입되었습니다.
-
5.2.0 E_RECOVERABLE_ERROR가 도입되었습니다.
-
5.0.0 E_STRICT 도입 (E_ALL의 일부가 아님).
참고 URL : https://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings
'Programing' 카테고리의 다른 글
JavaScript Date를 자정으로 초기화하는 가장 좋은 방법은 무엇입니까? (0) | 2020.02.23 |
---|---|
커밋 된 파일에 .gitignore 적용 (0) | 2020.02.23 |
C # if / then 지시어 대 디버그 대 릴리스 (0) | 2020.02.23 |
파일의 절대 경로를 인쇄하는 bash / fish 명령 (0) | 2020.02.23 |
JUnit4에서 특정 순서로 테스트 메소드를 실행하는 방법은 무엇입니까? (0) | 2020.02.23 |