php - Zend Registry in ZendFramework

Hello i am trying to override array value
So i have something like this.
Zend_Registry::set('config', $config);
$config is array
$config = ['timeZone' => 'GMT'];
is it possible to override just single value in already set array not whole array.
for Example something like this
Zend_Registry::set('config::timeZone', 'NewOne');
Zend_Reistry has inheritance from ArrayObject, so if that is possible in SPL ArrayObject, so if that is possible in SPL, it's possible here, but i can't find reference.
Answer
Solution:
It is possible, but not via theset
method. Theset
method simply callsArrayObject::offsetSet
, and there is no magic there. You're on the right track though, sinceZend_Registry
extendsArrayObject
, we can access the contents using standard array syntax, so you can treat an instance ofZendRegistry
like an array that has your config array at the index "config".
<?php
// Create our config array
$config = [
'country' => 'US',
'lang' => 'EN',
'timeZone' => 'EST'
];
// Set it in the registry
Zend_Registry::set('config', $config);
// Since registry extends ArrayObject, we can access the contents like an array
Zend_Registry::getInstance()['config']['timeZone'] = 'GMT';
// Get our config from the registry
$updatedConfig = Zend_Registry::get('config');
// Verify that the timeZone was updated
assert($updatedConfig['timeZone']=='GMT');
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string deprecated
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.