Hi,
I can't get the Zend_Registry to work as an object instead of an array.
I use the following code in the bootstrap file:
PHP Code:
# Load everything from config.ini.
$config = new Zend_Config_Ini('config.ini', null);
# Create a new Zend_Registry from the config.
$registry = new Zend_Registry($config->toArray(), ArrayObject::ARRAY_AS_PROPS);
# Unset the static instance.
Zend_Registry::_unsetInstance();
# Set the static instance.
Zend_Registry::setInstance($registry);
# Test.
$registry = Zend_Registry::getInstance();
echo $registry->system->name;
echo '<br />';
echo $registry->system->time->zone;
The content of config.ini is:
PHP Code:
[system]
name = "Zend_Registry Test"
time.zone = "Europe/Brussels"
[database]
username = "root"
password = "abc123!"
name = "zend"
hostname = "localhost"
type = "PDO_MYSQL"
I already checked the Zend Framework documentation. They warn you for using the ArrayObject::ARRAY_AS_PROPS parameter:
Quote:
|
Originally Posted by Zend Framework Documentation
25.1.5. Accessing the Registry as an Object
You may also find it convenient to access the registry in an object-oriented fashion, using index names as object properties. To do this, you need to specifically construct the registry object using the ArrayObject::ARRAY_AS_PROPS option, and initialize the static instance. You must do this before the static registry has been accessed for the first time. Beware of using this option, since some versions of PHP have bugs when using the registry with this option.
|
But I'm using the latest version of PHP (5.2.3), so that can't be the problem I guess? Can someone help me out here?
Thanks in advance for any response.
Kind regards