Only variables can be passed by reference

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

    array_pop() tries to change that value which is passed as parameter. Now in your second example this is the return value from array_slice(). In engine terms this is a "temporary value" and such a value can't be passed by references. what you need is a temporary variable:

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

    Then a reference to $b can be passed to array_pop(). See http://php.net/references for more details on references.

提交回复
热议问题