cphalcon
cphalcon copied to clipboard
[NFR] \Phalcon\Config implements ArrayAccess
It would be great if \Phalcon\Config would implements ArrayAccess interface.
For example:
<?php
use \Phalcon\Db\Adapter\Pdo\Mysql as PhMysql;
$config = new \Phalcon\Config(array
(
'db' => array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'name' => 'test',
),
));
// So it be able to call like this
new PhMysql($config->db);
// instead of this
new PhMysql(array(
"host" => $config->db->host,
"username" => $config->db->username,
"password" => $config->db->password,
"dbname" => $config->db->dbname,
));
Hi, Phalcon\Config now (0.8.0) supports accessing its elements using the array syntax, however, the framework is optimized to work with arrays. Reading objects using the ArrayAccess is slow, now you can pass the configuration this way:
new PhMysql($config->db->toArray());
//or
new PhMysql((array) $config->db);