


I encountered a problem while learning the CI framework today:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: user
Generally, no error will be reported when an undefined declared variable is output in the default ordinary PHP file. , but an error must be reported under the codeigniter framework. This is very inconvenient for "lazy people" who want to integrate adding and modifying pages. Since beginners are starting to think about how to block this error message in the code. Even using At @, but many people said that @ will greatly reduce performance...
Finally, I suddenly thought, did codeigniter intentionally prompt this error message? How should we block this type of error? I accidentally searched for it. " How do I prevent codeigniter from displaying Notice information?", I suddenly understood. It turned out that the error_reporting(E_ALL); in the entry index.php was causing trouble. Just change it to
error_reporting(E_ALL ^ E_NOTICE);
to block this error. It does not affect other error reports.
Here are some information found:
error_reporting() sets the error level of PHP and returns the current level.
Syntax
error_reporting(report_level)
If the parameter level is not specified, the current error level will be returned. The following are possible values for level:
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USE R_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
2047 E_ALL
2048 E_STRICT
E_NOTICE Indicates that the normal situation is not recorded, and is only used when the program has an error situation, such as trying to access a non-existent variable, or calling the stat() function to view a non-existent file.
E_WARNING is usually displayed but does not interrupt program execution. This is useful for debugging. For example: calling ereg() with the problematic regular notation.
E_ERROR is usually displayed and will interrupt program execution. This means that memory configuration or other errors cannot be traced using this mask.
E_PARSE Parse errors from syntax.
E_CORE_ERROR Like E_ERROR, but excludes errors caused by the PHP core.
E_CORE_WARNING Like E_WARNING, but does not include PHP core error warnings.
PHP Error Reporting
There are many configuration settings in the php.ini file. You should have already set up your php.ini file and placed it in the appropriate directory, as shown in the documentation for installing PHP and Apache 2 on Linux. There are two configuration variables that you should be aware of when debugging PHP applications. Here are the two variables and their default values:
display_errors = Off
error_reporting = E_ALL
The current default values of these two variables can be found by searching for them in the php.ini file. The purpose of the display_errors variable is obvious - it tells PHP whether to display errors. The default value is Off. However, to make the development process easier, set this value to On:
display_errors = On
The default value of the error_reporting variable is E_ALL. This setting will show everything from bad coding practices to harmless tips to errors. E_ALL is a bit too granular for development purposes, as it also displays hints on the screen for small things (such as variables not being initialized), which messes up the browser's output. I only want to see errors and bad coding practices, but not harmless tips. So, please replace the default value of error_reporting with the following value:
error_reporting = E_ALL & ~E_NOTICE
Restart Apache and you are all set. Next, you'll learn how to do the same thing on Apache.
Error reporting on the server
Depending on what Apache is doing, turning on error reporting in PHP may not work because there may be multiple versions of PHP on the computer. Sometimes it's difficult to tell which PHP version Apache is using because Apache can only look at one php.ini file. Not knowing which php.ini file Apache is using to configure itself is a security issue. However, there is a way to configure PHP variables in Apache so that the correct error level is set.
Also, it’s good to know how to set these configuration variables on the server side to override or preempt the php.ini file, thus providing a higher level of security.
When configuring Apache, you should have already touched the basic configuration in the http.conf file in /conf/httpd.conf.
To do what you have already done in the php.ini file, add the following lines to httpd.conf, overwriting any php.ini files:
php_flag display_errors on
php_value error_reporting 2039
This will override the php.ini file The flags that have been set for display_errors, and the value of error_reporting. The value 2039 represents E_ALL & ~E_NOTICE. If you prefer to use E_ALL, set the value to 2047. Again, you still need to restart Apache.
Next, we need to test the error reporting on the server.
Regarding the error_reporting() function, it can shield some error messages, but errors caused by the PHP core cannot be shielded, because errors caused by the PHP core will directly cause the PHP file compilation to fail, because the writing format does not follow PHP's Errors caused by writing coding rules cannot be blocked
Copy the code The code is as follows:
* For now, avoid warnings of E_STRICT mode
* (this must be done before function definitions)
*/
if (defined('E_STRICT')) {
$old_error_reporting = error_reporting(0);
if ($old_error_reporting & E_STRICT) {
error_reporting($old_error_reporting ^ E_STRICT);
} else {
error_reporting($old_error_reporting);
}
unset($old_error_reporting);
Common ones are as follows:
Copy code The code is as follows:
// Turn off all error reporting; Turn off all errors
error_reporting(0);
// Report simple running errors; reporting a simple running error
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings …); including reporting some uninitialized variable or catch typos in variable names
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
// This is the default value set in php.ini; Report all errors except E_NOTICE E_NOTICE This is also the default setting of php.ini
error_reporting(E_ALL ^ E_NOTICE);
// Report all PHP errors (bitwise 63 may be used in PHP 3); Report all errors
error_reporting(E_ALL);
// Same as error_reporting(E_ALL); Same as above
ini_set('error_reporting', E_ALL);
The above introduces the usage of the error_reporting function in crystal report PHP to modify PHP shielding errors, including the content of crystal report. I hope it will be helpful to friends who are interested in PHP tutorials.

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Laravel's service container and service providers are fundamental to its architecture. This article explores service containers, details service provider creation, registration, and demonstrates practical usage with examples. We'll begin with an ove

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.


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

SublimeText3 English version
Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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.

WebStorm Mac version
Useful JavaScript development tools

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