php - Zend Registry in ZendFrameworkGet the solution ↓↓↓
Hello i am trying to override array value
So i have something like this.
$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_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.
It is possible, but not via the
set method. The
set method simply calls
ArrayObject::offsetSet, and there is no magic there. You're on the right track though, since
ArrayObject, we can access the contents using standard array syntax, so you can treat an instance of
ZendRegistry 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');
People are also looking for solutions of the problem: installation failed, reverting ./composer.json and ./composer.lock to their original content.
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.
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.