read-only properties in PHP?

前端 未结 4 617
清歌不尽
清歌不尽 2021-01-17 14:18

Is there a way to make a read-only property of an object in PHP? I have an object with a couple arrays in it. I want to access them as I normally would an array

<         


        
4条回答
  •  清歌不尽
    2021-01-17 15:05

    in the class, do this:

    private $array;
    
    function set_array($value) {
        $this->array = $value;
    }
    

    then you just set like this:

    $obj->set_array($new_array);
    

提交回复
热议问题