What should I do if the new addition in php7 does not report undefined?
php7 new addition will not report undefined Solution: 1. Change the error reporting level of PHP by modifying the php.ini file; 2. Use the error_reporting function in the code to dynamically set the error reporting level; 3. Use functions such as isset and empty to check whether the variable has been determined; 4. Use PHP's strict mode to force variables to be declared before use, so that potential problems can be discovered and repaired earlier.
The operating environment of this article: Windows 10 system, PHP7.4 version, Dell G3 computer.
In PHP 7, when we access an undefined variable or call an undefined function, an error will no longer be reported. Instead, an E_NOTICE level error will be thrown and a NULL value will be returned. This change in behavior is intended to improve code robustness and readability.
However, for some developers, they may hope to still get undefined variable errors in PHP 7 so that potential problems can be discovered and fixed in time. Fortunately, PHP 7 provides some options to control this behavior.
1. Change the error reporting level of PHP by modifying the php.ini file.
In the php.ini file, you can find a configuration item called error_reporting, which determines which errors PHP should report. By default, the value of this configuration item is E_ALL & ~E_NOTICE, which means that PHP will report all errors except E_NOTICE level errors. We can modify this to E_ALL to enable reporting of all errors, including errors for undefined variables.
2. Use the error_reporting function in the code to dynamically set the error reporting level.
For example, we can use the following statement at the beginning of the code to enable the reporting of all errors:
error_reporting(E_ALL);
3. Use functions such as isset and empty to check whether the variable has been definition.
These functions can help us judge before accessing variables and avoid using undefined variables.
4. Use PHP's strict mode to force variables to be declared before use.
Strict mode can be enabled by adding the following statement at the beginning of the code:
declare(strict_types=1);
In strict mode, PHP will throw an error when accessing an undefined variable and not It is automatically initialized to NULL. This helps us detect and fix potential problems earlier.
Summary
If we want to still get the error of undefined variables in PHP 7, we can change the error by modifying the php.ini file or using the error_reporting function Report level, use functions like isset and empty to check if a variable is defined, and enable strict mode to enforce declaration of variables. These methods can help us discover and fix potential problems in a timely manner during the development process, and improve the robustness and readability of the code.
The above is the detailed content of What should I do if the new addition in php7 does not report undefined?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor