Paramétrage du niveau d'erreur PHP et analyse des principes

不言
Libérer: 2023-03-25 11:04:01
original
1477 Les gens l'ont consulté

Cet article présente principalement le paramètre de niveau d'erreur PHP et l'analyse du principe. Il a une certaine valeur de référence. Maintenant, je le partage avec tout le monde. Les amis dans le besoin peuvent s'y référer

Introduction au principe

Dans le fichier de configuration PHP, php.ini a la configuration suivante :

; 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-reportingerror_reporting = E_ALL
Copier après la connexion

Dans la configuration ci-dessus : error_reporting sert à définir le niveau de configuration par défaut E_ALL, ce qui signifie ; afficher toutes les informations d'avis, d'avertissement et d'erreur (Afficher toutes les erreurs, avertissements et avis, y compris les normes de codage.).
C'est expliqué en détail dans le manuel PHP Constantes prédéfinies, ce qui suit fait partie de l'extrait :

Exemple : E_ALL & ~E_NOTICE
E_TOUS : 111011111111111
E_NOTICE : 1000
~E_NOTICE : 0111
E_ALL & ~E_NOTICE : 111011111110111

C'est ainsi que php contrôle le niveau d'erreur via la conversion binaire.

Ajustez le niveau d'erreur

Paramètres globaux

Modifiez le rapport d'erreur dans le fichier php.ini pour obtenir l'effet.
Par exemple :

1. error_reporting = E_ALL #输出所有错误,警告,notice信息
2. error_reporting = E_ALL & ~E_NOTICE #输出所有错误和警告信息,不输出notice信息
3. E_ALL & ~E_NOTICE & ~E_WARNING #输出所有错误信息,不输出警告,notice信息
Copier après la connexion

Paramètres locaux

Dans un script ou un programme, l'effet peut être obtenu via les paramètres ini_set() et error_reporting().
Par exemple :

ini_set("display_errors",1)
error_reporting(E_ALL)
Copier après la connexion

相关推荐:

<a href="http://www.php.cn/php-weizijiaocheng-392917.html" target="_self">PHP报错并自动跳转</a>

Gestion des erreurs PHP en mode développement et en mode produit

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!