Only variables can be passed by reference

前端 未结 8 1235
小鲜肉
小鲜肉 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:22

    It's a memory corruption issue (according to PHP dev team). Just throw in an assignment:

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

    :

    function foo(){
        $a = explode( '/' , 'a/b/c');
        $c = array_pop($arr = array_slice($a,-2,1));
        return $c;
    }
    print_r(foo());
    

    The second produces an E_STRICT. You can handle that differently in your error handler if you wish (if you don't want to change those functions).

提交回复
热议问题