PHP set magic method with array as names

前端 未结 4 1468
無奈伤痛
無奈伤痛 2020-12-21 09:13

I am creating a class which I will use to store and load some settings. Inside the class all settings are stored in an array. The settings can be nested, so the settings arr

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-21 09:32

    When accessing an array using this method, it actually goes through __get instead. In order to set a parameter on that array that was returned it needs to be returned as a reference: &__get($name)

    Unless, what you mean is that you want each item that is returned as an array to act the same way as the parent object, in which case you should take a look at Zend Framework's Zend_Config object source for a good way to do that. (It returns a new instance of itself with the sub-array as the parameter).

提交回复
热议问题