PHP:大量使用stdClass对象而不是关联数组?

时间:2014-08-02 19:44:59

标签: php codeigniter

我已经开始在MVC(CodeIgniter)项目中大量使用stdClass对象。这种方法有不妥之处吗?

我使用对象的原因是我觉得它比关联数组更具可读性。

这是一个片段:

    $param = new stdClass();

    $param->search = $this->get('search');
    $param->country = $this->get('country');
    $param->rating = $this->get('rating');
    $param->select_filter = 
    '
        users.id, 
        users.username, 
        users.display_name, 
        users.picture, 
        users.country_code, 
        users.about, 
        avg(rating) as rate, ;

    $this->db->select($param->select_filter); // customize later
    $this->db->like('users.username', $param->search);
    $this->db->from('users');
    //some other join stuff here
    $this->db->group_by('users.id');

    $result = new stdClass();
    $result->users = $this->db->get()->result();

0 个答案:

没有答案