cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[NFR] \Phalcon\Config implements ArrayAccess

Open iforp opened this issue 14 years ago • 1 comments

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,
));

iforp avatar Nov 29 '12 16:11 iforp

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);

ghost avatar Dec 16 '12 11:12 ghost