Only variables can be passed by reference

前端 未结 8 1226
小鲜肉
小鲜肉 2020-12-11 00:59

I had the bright idea of using a custom error handler which led me down a rabbit hole.

Following code gives (with and without custom error handler): Fatal er

8条回答
  •  無奈伤痛
    2020-12-11 01:24

    array_pop() changes that value passed to it which is where the error is coming from. A function cannot be changed. In other words, you need to assign the array to a variable first (ref: manual), and then run array_pop().

    The code you need is this:

    function foo(){
        $a = array("a","b","c");
        $b = array_pop($a);
        return $b;
    }
    

    Edit: Both functions you mentioned have the same problem. Assign the array to a variable and pass the variable to array_pop().

提交回复
热议问题