Get error name php

PHP Error Functions

The error functions are used to deal with error handling and logging.

The error functions allow us to define own error handling rules, and modify the way the errors can be logged.

The logging functions allow us to send messages directly to other machines, emails, or system logs.

The error reporting functions allow us to customize what level and kind of error feedback is given.

Installation

The PHP error functions are part of the PHP core. No installation is required to use these functions.

Runtime Configuration

The behavior of the error functions is affected by settings in php.ini.

Errors and logging configuration options:

Name Default Description Changeable
error_reporting NULL Sets the error reporting level (either an integer or named constants) PHP_INI_ALL
display_errors «1» Specifies whether errors should be printed to the screen, or if they should be hidden from the user.
Note: This feature should never be used on production systems (only to support your development)
PHP_INI_ALL
display_startup_errors «0» Even when display_errors is on, errors that occur during PHP’s startup sequence are not displayed
Note: It is strongly recommended to keep display_startup_errors off, except for debugging
PHP_INI_ALL
log_errors «0» Defines whether script error messages should be logged to the server’s error log or error_log.
Note: It is strongly advised to use error logging instead of error displaying on production web sites
PHP_INI_ALL
log_errors_max_len «1024» Sets the maximum length of log_errors in bytes. The value «0» can be used to not apply any maximum length at all. This length is applied to logged errors, displayed errors, and also to $php_errormsg (available since PHP 4.3) PHP_INI_ALL
ignore_repeated_errors «0» Specifies whether to log repeated error messages. When set to «1» it will not log errors with repeated errors from the same file on the same line (available since PHP 4.3) PHP_INI_ALL
ignore_repeated_source «0» Specifies whether to log repeated error messages. When set to «1» it will not log errors with repeated errors from different files or source lines (available since PHP 4.3) PHP_INI_ALL
report_memleaks «1» If set to «1» (the default), this parameter will show a report of memory leaks detected by the Zend memory manager (available since PHP 4.3) PHP_INI_ALL
track_errors «0» If set to «1», the last error message will always be present in the variable $php_errormsg PHP_INI_ALL
html_errors «1» Turns off HTML tags in error messages PHP_INI_ALL
PHP_INI_SYSTEM in PHP
xmlrpc_errors «0» Turns off normal error reporting and formats errors as XML-RPC error message (available since PHP 4.1) PHP_INI_SYSTEM
xmlrpc_error_number «0» Used as the value of the XML-RPC faultCode element (available since PHP 4.1) PHP_INI_ALL
docref_root «» (available since PHP 4.3) PHP_INI_ALL
docref_ext «» (available since PHP 4.3.2) PHP_INI_ALL
error_prepend_string NULL Specifies a string to output before an error message PHP_INI_ALL
error_append_string NULL Specifies a string to output after an error message PHP_INI_ALL
error_log NULL Specifies the name of the file where script errors should be logged. The file should be writable by the web server’s user. If the special value syslog is used, the errors are sent to the system logger instead PHP_INI_ALL

PHP Error and Logging Functions

Function Description
debug_backtrace() Generates a backtrace
debug_print_backtrace() Prints a backtrace
error_clear_last() Clears the last error
error_get_last() Returns the last error that occurred
error_log() Sends an error message to a log, to a file, or to a mail account
error_reporting() Specifies which errors are reported
restore_error_handler() Restores the previous error handler
restore_exception_handler() Restores the previous exception handler
set_error_handler() Sets a user-defined error handler function
set_exception_handler() Sets a user-defined exception handler function
trigger_error() Creates a user-level error message
user_error() Alias of trigger_error()

PHP Predefined Error and Logging Constants

Value Constant Description
1 E_ERROR Fatal run-time errors. Errors that cannot be recovered from. Execution of the script is halted
2 E_WARNING Run-time warnings (non-fatal errors). Execution of the script is not halted
4 E_PARSE Compile-time parse errors. Parse errors should only be generated by the parser
8 E_NOTICE Run-time notices. The script found something that might be an error, but could also happen when running a script normally
16 E_CORE_ERROR Fatal errors at PHP startup. This is like E_ERROR, except it is generated by the core of PHP
32 E_CORE_WARNING Non-fatal errors at PHP startup. This is like E_WARNING, except it is generated by the core of PHP
64 E_COMPILE_ERROR Fatal compile-time errors. This is like E_ERROR, except it is generated by the Zend Scripting Engine
128 E_COMPILE_WARNING Non-fatal compile-time errors. This is like E_WARNING, except it is generated by the Zend Scripting Engine
256 E_USER_ERROR Fatal user-generated error. This is like E_ERROR, except it is generated in PHP code by using the PHP function trigger_error()
512 E_USER_WARNING Non-fatal user-generated warning. This is like E_WARNING, except it is generated in PHP code by using the PHP function trigger_error()
1024 E_USER_NOTICE User-generated notice. This is like E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error()
2048 E_STRICT Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code (Since PHP 5 but not included in E_ALL until PHP 5.4)
4096 E_RECOVERABLE_ERROR Catchable fatal error. Indicates that a probably dangerous error occurred, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle, the application aborts as it was an E_ERROR (Since PHP 5.2)
8192 E_DEPRECATED Run-time notices. Enable this to receive warnings about code that will not work in future versions (Since PHP 5.3)
16384 E_USER_DEPRECATED User-generated warning message. This is like E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error() (Since PHP 5.3)
32767 E_ALL Enable all PHP errors and warnings (except E_STRICT in versions < 5.4)

Источник

constants — PHP error handler — how to get error name

i have my own error_handler:

$error = new Error(); set_error_handler(array($error,"catchError")); class Error < public function catchError($err_no, $err_str, $err_file, $err_line, $err_context)< print_r($err_no); >> 

If i cause error of type «E_WARNING» this error catcher writes just «2». How i force him to write «E_WRNING»?

I wonder, if is possible get error name from this «2» code. Thank you very much!

Answer

Solution:

$errors = array( E_WARNING => 'E_WARNING', E_NOTICE => 'E_NOTICE', . ); echo $errors[$err_no]; 

For all types you want to handle from this list: http://php.net/manual/en/errorfunc.constants.php
Typically you’d handle different error levels differently, not just echo the name of the constant.

Share solution ↓

Additional Information:

Didn’t find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Similar questions

Find the answer in similar questions on our website.

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

About the technologies asked in this question

PHP

PHP (from the English Hypertext Preprocessor — hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites. The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/

Welcome to programmierfrage.com

programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.

Get answers to specific questions

Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.

Help Others Solve Their Issues

Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.

Источник

Predefined Constants

The constants below are always available as part of the PHP core.

Note: You may use these constant names in php.ini but not outside of PHP, like in httpd.conf , where you’d use the bitmask values instead.

Errors and Logging
Value Constant Description Note
1 E_ERROR ( int ) Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.
2 E_WARNING ( int ) Run-time warnings (non-fatal errors). Execution of the script is not halted.
4 E_PARSE ( int ) Compile-time parse errors. Parse errors should only be generated by the parser.
8 E_NOTICE ( int ) Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
16 E_CORE_ERROR ( int ) Fatal errors that occur during PHP’s initial startup. This is like an E_ERROR , except it is generated by the core of PHP.
32 E_CORE_WARNING ( int ) Warnings (non-fatal errors) that occur during PHP’s initial startup. This is like an E_WARNING , except it is generated by the core of PHP.
64 E_COMPILE_ERROR ( int ) Fatal compile-time errors. This is like an E_ERROR , except it is generated by the Zend Scripting Engine.
128 E_COMPILE_WARNING ( int ) Compile-time warnings (non-fatal errors). This is like an E_WARNING , except it is generated by the Zend Scripting Engine.
256 E_USER_ERROR ( int ) User-generated error message. This is like an E_ERROR , except it is generated in PHP code by using the PHP function trigger_error() .
512 E_USER_WARNING ( int ) User-generated warning message. This is like an E_WARNING , except it is generated in PHP code by using the PHP function trigger_error() .
1024 E_USER_NOTICE ( int ) User-generated notice message. This is like an E_NOTICE , except it is generated in PHP code by using the PHP function trigger_error() .
2048 E_STRICT ( int ) Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.
4096 E_RECOVERABLE_ERROR ( int ) Catchable fatal error. It indicates that a probably dangerous error occurred, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler() ), the application aborts as it was an E_ERROR .
8192 E_DEPRECATED ( int ) Run-time notices. Enable this to receive warnings about code that will not work in future versions.
16384 E_USER_DEPRECATED ( int ) User-generated warning message. This is like an E_DEPRECATED , except it is generated in PHP code by using the PHP function trigger_error() .
32767 E_ALL ( int ) All errors, warnings, and notices.

The above values (either numerical or symbolic) are used to build up a bitmask that specifies which errors to report. You can use the bitwise operators to combine these values or mask out certain types of errors. Note that only ‘|’, ‘~’, ‘!’, ‘^’ and ‘&’ will be understood within php.ini .

Источник

Читайте также:  Edu ru modules php
Оцените статью