How to use __get() to return null in multilevel object property accessing?

前端 未结 3 1561
北恋
北恋 2021-01-21 02:31

How can I use __get() to return null in multilevel object property accessing the case like this below?

For instance, this is my classes,

class property          


        
3条回答
  •  野的像风
    2021-01-21 02:51

    You can can return new property instead of null

     public function __get($name)
        {
            return (isset($this->$name)) ? $this->$name : new property();
        }
    

提交回复
热议问题