鍍金池/ 問答/PHP/ php7.2的&引用問題

php7.2的&引用問題

 /**
     * 執(zhí)行樹形數(shù)據(jù)生成 非遞歸實(shí)現(xiàn)
     * @author RuizhaoLee <liruizhao970302@outlook.com>
     * @param  array $array      要進(jìn)行轉(zhuǎn)化的數(shù)組
     * @param  string $returnType 轉(zhuǎn)化的結(jié)果返回模式,支持array|json
     * @param  string $children   子節(jié)點(diǎn)下標(biāo),默認(rèn)'children'
     * @param  string $defaultId  id節(jié)點(diǎn)下標(biāo),默認(rèn)'id'
     * @param  string $defaultPar 父id節(jié)點(diǎn)下標(biāo),默認(rèn)'pid'
     * @return onject
     */
    public function mark($data, $children = 'children', $defaultId = 'id', $defaultPar = 'pid')
    {
        $data = $this->collection($data);
        $tree = [];
        foreach ($data as $item) {
            $tree[$item[$defaultId]] = $item;
            $tree[$item[$defaultId]][$children] = [];
        }

        foreach ($tree as $key => $item) {
            if ($item[$defaultPar] != 0) {
                $tree[$item[$defaultPar]][$children][] = &$tree[$key];
                if (empty($tree[$key][$children])) unset($tree[$key][$children]);
            }
        }

        foreach ($tree as $key => &$item) {
            if ($item[$defaultPar] != 0) unset($tree[$key]);
            if (empty($item[$children])) unset($item[$children]);
        }

        $this->tree = $tree;
        return $this;
    }

這段代碼在低于7.0的版本中沒有問題,轉(zhuǎn)到7.2就報(bào)錯了.報(bào)錯內(nèi)容如下:

clipboard.png

出錯行數(shù)在
clipboard.png

個人覺得是&引用的問題 百度搜索過沒有答案,希望能得到答案謝謝~

回答
編輯回答
念初

引用一般是用在方法的參數(shù)傳遞吧,沒這樣用過

2017年3月29日 08:03