PHP's assignment by reference is not working as expected

后端 未结 7 1548
迷失自我
迷失自我 2021-01-29 08:04

Why the following

class AClass
{
    public function __construct ()
    {
        $this->prop = \"Hello\";
    }
    public function &get ()
    {
                


        
7条回答
  •  抹茶落季
    2021-01-29 08:39

    You should remove the ampersand in your func function. Then it will return you the string.

    function func (&$ref)
    {
        $ref = $ref->get();
    }
    

提交回复
热议问题