note 126465 added to errorfunc.constants

From: Date: Wed, 29 Sep 2021 18:57:13 +0000
Subject: note 126465 added to errorfunc.constants
Groups: php.notes 
Request: Send a blank email to php-notes+get-217015@lists.php.net to get a copy of this message
A simple and neat way to get the error level from the error code. You can even customize the error level names further. <?php $exceptions = [ E_ERROR => "E_ERROR", E_WARNING => "E_WARNING", E_PARSE => "E_PARSE", E_NOTICE => "E_NOTICE", E_CORE_ERROR => "E_CORE_ERROR", E_CORE_WARNING => "E_CORE_WARNING", E_COMPILE_ERROR => "E_COMPILE_ERROR", E_COMPILE_WARNING => "E_COMPILE_WARNING", E_USER_ERROR => "E_USER_ERROR", E_USER_WARNING => "E_USER_WARNING", E_USER_NOTICE => "E_USER_NOTICE", E_STRICT => "E_STRICT", E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", E_DEPRECATED => "E_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED", E_ALL => "E_ALL" ]; echo $exceptions["1"]; $code = 256; echo $exceptions[$code]; ?> Output: E_ERROR E_USER_ERROR This will need updating when PHP updates the error level names. Otherwise, it works just fine. ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 102.22.211.24) ---- Manual Page -- https://php.net/manual/en/errorfunc.constants.php Edit -- https://main.php.net/note/edit/126465 Del: integrated -- https://main.php.net/note/delete/126465/integrated Del: useless -- https://main.php.net/note/delete/126465/useless Del: bad code -- https://main.php.net/note/delete/126465/bad+code Del: spam -- https://main.php.net/note/delete/126465/spam Del: non-english -- https://main.php.net/note/delete/126465/non-english Del: in docs -- https://main.php.net/note/delete/126465/in+docs Del: other reasons-- https://main.php.net/note/delete/126465 Reject -- https://main.php.net/note/reject/126465 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217015) next »