PHP through the trigger

Source: Internet
Author: User
Tags php error

This article mainly introduces PHP through the trigger_error to trigger a PHP error example, this article describes the error suppressor @ and through the Trigger_error trigger PHP error example, the need for friends can refer to the

Example of PHP error triggered by Trigger_error in PHP

"Error suppressor @"

In addition to the error_reporting and display_errors settings in PHP.ini, the error_reporting () function, the Ini_set () function, you can also use the error suppressor @ to mask the wrong output.

@ Plus before any expression that will produce an error.

"Trigger PHP error via Trigger_error"

The ability to trigger the error is not limited to the PHP parser, it can also trigger an error through the Trigger_error () function, similar to the exception thrown in the exception, throws an error that can assist in debugging the code.

Cases

The code is as follows:

  

$num 1 = 1;

$num 2 = ' 2 ';

if (!) ( Is_numeric ($num 1) && is_numeric ($num 2))) {

Error of manually throwing notification level

Trigger_error (' Num1 and num2 must be legal values ', e_user_notice);

}else{

echo $num 1 + $num 2;

}

Echo '
The program continues to execute downward ';

Output:

The code is as follows:

3

Program continues down execution

and

The code is as follows:

  

$num 1 = 1;

$num 2 = ' 2a ';

if (!) ( Is_numeric ($num 1) && is_numeric ($num 2))) {

Error of manually throwing notification level

Trigger_error (' Num1 and num2 must be legal values ', e_user_notice);

}else{

echo $num 1 + $num 2;

}

Echo '
The program continues to execute downward ';

Output:

The code is as follows:

( ! ) NOTICE:NUM1 and num2 must be valid values in d:practisephperrorerror1.php on line 6

Program continues down execution

"Other" when serious errors such as the database is not connected, you can manually throw the error-replace the PHP built-in e_warning warning with E_user_error.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.