Error reporting with reference to parameters and recursive escape

Source: Internet
Author: User

The following example:

$age = 10;function Grow ($age) {    $age + = 1;    return $age;} Echo Grow (& $age), ' <br/> ';  11echo $age, ' <br/> ';         11

In the previous example, the global variable was also affected after the function was called.
Because we do "reference", this way, contrary to the concept of "encapsulation", affecting the cleanliness of the code.
Therefore, it is not recommended to do so.

In Php5.3,php.ini, there is an option, as follows

Allow_call_time_pass_reference = Off

If off, the function references the Warning:call-time pass-by-reference has been deprecated if on, does not report warning

in PHP5.4 , the function reference is completely abolished, and when a function is used to reference the parameter,
reported fatal error: Call-time pass-by-reference has been removed


Workaround:
1:allow_call_time_pass_reference = On But this is not a fundamental solution, if porting 5.4, or not.
2: Modify your own code, do not reference the function of the argument.

Function:

Recursive escape Array function _addslashes ($arr) {    foreach ($arr as $k = = $v) {        if (is_string ($v)) {            $arr [$k] = Addslashes ($v);        } else if (Is_array ($v)) {  //plus judgment, if it is an array, call itself, then go            $arr [$k] = _addslashes ($v);}    }        return $arr;}

Error reporting with reference to parameters and recursive escape

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.