php深度克隆仍然会改变价值

时间:2015-01-28 16:18:51

标签: php codeigniter object clone

我有以下功能:

$results_array = array();

        foreach($results as $row) {

            $t = time();
            $t = $this->load->library('Funding_Opportunity_L', '', $t);

            // Starting to build object
            $t->opp_name = $row->name;
            $t->description = $row->description;



            // Allocate funder
            $t->funder = $this->funders_model->getFromId($row->funder);
            echo $t->funder->name . " ";
            // Allocate duration
            $t->date_range = $this->date_range_model->getFromId($row->duration);

            // Allocate career stage
            $t->career_stages = $this->career_stage_model->getAllMatchingOpportunities($row->id);

            // Allocate type
            $t->types = $this->type_model->getAllMatchingOpportunities($row->id);
            $tt = clone $t;
            array_push($results_array, clone $t);

            unset($t);

        }

        $r = $results_array[0];
        echo $r->funder->name;

        $r = $results_array[1];
        echo $r->funder->name;
        return $results_array;

在foreach循环(第一个echo语句)中回显两个不同的结果,但是当从数组中读取值时,只回显后一个值。我不明白我做错了什么,因为我克隆了对象而不是通过引用添加它并取消设置对象?

0 个答案:

没有答案