Table of Contents
Syntax
How display_errors work in PHP?
Examples
Example #3
Conclusion

PHP display_errors

Aug 29, 2024 pm 01:06 PM
php

PHP display_errors have some function that is used to define the list of errors and warnings with appropriate and detailed information. PHP display_errors provide aid to developers concerning troubleshooting and debugging. Any application related to PHP gets halted and stopped due to some reason will include some set of errors or warning that needs to be displayed as part of PHP display_errors. There are different levels of errors involved as part of display_errors at the time of execution. PHP Display_error order mentioned in the document should always be in “ON” mode when present within the document.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax

There is no proper syntax for PHP display_errors, but still, some set of lines of codes with a specific format needs to be included within the script at the time of execution of PHP code at the time of execution. The line of codes is represented as follows :

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
Copy after login

where,

  • ini_set(): This is the function that mainly will try to override the configuration found initially in the ini file.
  • display_errors: It is one of the directives that will determine whether there is a need to determine the error or remain hidden from the end-user.
  • display_startup_errors: It is another directive that is also behaving similarly as display_errors with a difference in the fact that the display startup error will be responsible for fetching all the errors at the startup time the screen.
  • error_reporting(): Error reporting function acts like a filter which is mostly responsible for filtering out the errors necessary for display.
  • E-ALL: It is the most recommended directive by developers as it provides more understandable and readable formats to developers.

How display_errors work in PHP?

  • PHP has a good significance for display_errors as it gives the programmers the ability to troubleshoot and provide a proper readable and understandable format of code.
  • It lets programmers debug with the detailed set of information concerning errors and warnings it provides.
  • The easiest way to achieve the display of all kinds of errors in PHP is to include some set of statements or codes within the ini file at the time of execution and compilation.
  • It helps in achieving the detailed display of error while execution by including some lines of code within the ini file as mentioned in the syntax.
  • Each function with the arguments passed on to the function has its own significance.
  • Ini() function always try to override the current configuration present within the ini file of PHP, and two directives make use of the ini function religiously. Both the two directives have their own role.
  • Display error directive is used whenever the need to display the error is not mandatory, and at the time of development, the display_error directive should be kept off; otherwise, it will create a hurdle.
  • On the contrary, display_startup_error has a different significance in the sense it is used only when the code execution gets started with the startup sequence as the Display error directive never participates for the same. It always makes use of the ini function to provide total functionality.
  • Also, some more interesting characteristics are involved related to both the directives; that is, they won’t be able to display any kind of Parse errors. Suppose in case the programmers forget to put the semicolon or some misses to put the curly braces than in that case it will be a problem for programmers as mentioned with the reason.
  • Sometimes it happens that in the real-time environment or testing environment, it becomes difficult to test with the already mentioned directives; then, in that case, there is the usage of some additional directives that need to be made either on or off to handle the implementation of code with the browser.
  • A solution to the above scenario is to make the display_error directive as ON using the following command to be included in the ini file as display_error = on. Then restart the apache tomcat folder by restoring the ini file in a working folder of apache tomcat.
  • This way, the ini_set() function will incorporate all the major directives as parameters and pass them accordingly at the time of execution of code.

Examples

Here are the following examples mention below

Example #1

This program demonstrates the inclusion of a set of code within the ini file, but it fails as the display error and display startup error does not include parse errors depicting the exact location of the failure within the file and the output as shown.

Code:

<!DOCTYPE html>
<html>
<body>
<?php
ini_set('display_errors', 1);
ini_set('display_start_up_errors', 1);
error_reporting(E_ALL);
include("abcd.php");
?>
</body>
</html>
Copy after login

Output:

PHP display_errors

Note: To get the above error displayed in the proper understandable and readable format, then it is very much needed to display errors, including parse errors for which it is needed to make a change in php.ini or pgp-fpm in apache tomcat, i.e. in the working folder of apache tomcat with the following command as part of the configuration file: display_errors = ON.

Example #2

This program demonstrates other types of errors that can be displayed, not necessarily including the overall PHP display_error functions. But sometimes, these kinds of errors or warnings come up with the developers as execution is almost smooth and should get easily solved.

Code:

<!DOCTYPE html>
<html>
<body>
<?php
$z = "Representation_of_Notice_Error.";
echo $z;
echo $Notice;
?>
</body>
</html>
Copy after login

Output:

PHP display_errors

Example #3

This program demonstrates that the display_error with ini() function is enabled and restarted, as shown in the output. This warning comes into the picture when the display_error is enabled and restarted in the apache tomcat working folder.

Code:

<!DOCTYPE html>
<html>
<body>
<?php
for($h_1 = 1; $h_1 <= 8 $h_1++)
{
echo $h_1;
}
?>
</body>
</html>
Copy after login

Output:

PHP display_errors

Conclusion

PHP display_error is quite an appropriate functionality as part of PHP and provides aid to programmers by providing them with the ability and flexibility to troubleshoot and debug the application easily. It makes the time consumption of debugging and troubleshooting less. Overall, It is a very efficient approach to use display_errors in PHP to get detailed information for errors and warnings as it helps in many ways.

The above is the detailed content of PHP display_errors. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

See all articles