danallen Posted December 18, 2015 Share Posted December 18, 2015 Hi, sometimes simple things are hard. I asked at the pub down the street, but no one had a clue. How do we reference the property [sess_expiration] in the object below? Seems like it should be possible to use $this->config->config->sess_expiration Array( [config] => Config Object ( [config] => Array ( [sess_cookie_name] => weird_session [sess_expiration] => 2592000 ) ) ) This does the job, but this is stupid-looking: $value_i_need=get_object_vars(get_object_vars($this)['config'])['config']['sess_expiration'] If you could fill me in on how to deal with this, I would really appreciate it. Thank you. Quote Link to comment Share on other sites More sharing options...
requinix Posted December 18, 2015 Share Posted December 18, 2015 Looks like you did a print_r(get_object_vars($this))Right? 1. The thing you printed is an array, because that's what get_object_vars does. But $this is an object. 2. "config" is the thing inside it. 3. It is an object (a Config object). 4. "config" is (again) the next thing inside it. 5. It is an array. 6. "sess_expiration" is one of the values you want. Objects use -> and arrays use []. $this->config->config["sess_expiration"] Quote Link to comment Share on other sites More sharing options...
danallen Posted January 21, 2017 Author Share Posted January 21, 2017 It's been awhile since posting this, but I still appreciate the response. Usually, I am working with arrays. I have had occasion to catch up to a degree on php objects, how and why they are used, read some discussions of trade-offs, and after all that, I would have to say, your explanation is exactly perfect from my perspective, so thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.