Only variables can be passed by reference

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

    I think that now (since php 5) it should be:

    function &foo(){ //NOTICE THE &
        $b=array_pop(array("a","b","c"));
        return $b;
    }
    print_r(foo());
    

    and

    function &foo(){ //NOTICE THE &
        $a=explode( '/' , 'a/b/c');
        $c=array_pop(array_slice($a, $b = -2, $c = 1)); //NOW NO DIRECT VALUES ARE PASSED IT MUST BE VARIABLES
        return $c;
    }
    print_r(foo());
    

    but i'm just a begginer :)

提交回复
热议问题