PHP error Suppressor (@) causes an analysis of a bug that references a failed argument _php tutorial

Source: Internet
Author: User
Tags php error
Look at the following example:
Copy CodeThe code is as follows:
$array = Array (+/-);
function Add (& $arr) {
$arr [] = 4;
}
Add (@ $array);
Print_r ($array);
/**
At this point, the $array does not change, output:
Array
(
[0] = 1
[1] = 2
[2] = 3
)
*/
Add ($array);
Print_r ($array);
/**
With no error suppression, the output is normal:
Array
(
[0] = 1
[1] = 2
[2] = 3
[3] = 4
)
*/
?>

This problem, I have not met before, so first to find relevant information, see if there is a ready-made answer, Goolge, found that although someone has reported to PHP similar bug:http://bugs.php.net/bug.php?id=47623, However, the official PHP has not been resolved, and did not give a reply.

No way, you can only analyze, and I have introduced the principle of the error suppressor in the article (in-depth understanding of the PHP principle of error suppression and embedded HTML), in principle, the error suppression is only modified error_reporting level, The mechanism of function calls between contexts is not normally affected. Only through field trials.

The

has been traced by GDB and found that the arguments opcode before the function call were different after using the wrong migration character:
Copy the code code as follows:
//Do not use the error suppressor when
OPCODE = Send_ref
//After using the error suppression symbol
OPCODE = send_var_no_re

At the beginning of the issue Step, but what is the reason for this difference?

Since the opcode is different, then certainly in the grammar analysis stage, walked the different branch, thought this layer, the question also is good to locate,

Originally, the PHP parsing stage, the shape is like "@" +expr the entry, the statute became Expr_without_ Variable, the meaning of this node is that there is no value for the variable, that is, the literal, and we all know that the literal value cannot be passed (because it is not a variable), so this difference is caused. The

procedure is as follows:
1. Parsing phase:
copy code The code is as follows:
Expr_without_variable:
//... There are omitted
| ' @ ' {zend_do_begin_silence (&$1 tsrmls_cc);}
Expr {zend_do_end_silence (&$1 tsrmls_cc); $$ = $ $;}
//Here Go Zend_send_val branch
Non_empty_function_call_parameter_list:
expr_without_variable {...}//Wrong Walk this branch
| variable {...}/normal

so a different opcode was generated during compilation, which also leads to the appearance of the problem.
Finally, I have explained the reason in the PHP bug page, interested can go to see my poor English level. Finally, thank you for this interesting question CiCi.

http://www.bkjia.com/PHPjc/323224.html www.bkjia.com true http://www.bkjia.com/PHPjc/323224.html techarticle Take a look at the following example: The copy code is as follows: PHP $array = array, function add (@ $array); Print_r ($array);/** at this time, the $array does not change, output: Array ([0] = 1 [1 ...

  • 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.