We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Bug with Phalcon\Config ? (not sure, but seems a bit odd)

Hi all,

I'm building an app that has 2 sets of config parameters:

  • A first set loaded from an INI file with \Phalcon\Config\Adapter\Ini (platfom config)
  • And a second one coming dynamically from the database. This second config is loaded into a \Phalcon\Config

Funny behaviour when I try to merge those 2 objects using the provided "merge" method:

$oDynConf->merge($oIniConf); ==> works fine.

$oIniConf->merge($oDynConf); ==> Invalid callback Phalcon\Config\Adapter\Ini::_merge, cannot access private method Phalcon\Config\Adapter\Ini::_merge() in /data/www/nis/app/config/dynamic-config.php at line 37

Am I doing something wrong or is there a scope issue there. Seems like despite inheriting from \Phalcon config, the \adapter can merge properly.

Best.



51.2k

config.ini

[database]
adapter  = Mysql
host     = localhost
username = scott
password = cheetah
dbname     = test_db

[phalcon]
controllersDir = "../app/controllers/"
modelsDir      = "../app/models/"
viewsDir       = "../app/views/"

[models]
metadata.adapter  = "Memory"

test.php

<?php
$ini = new \Phalcon\Config\Adapter\Ini("config.ini");

$arr = new \Phalcon\Config(array(
    'database' => array(
        'username' => 'scott',
        'password' => 'secret',
    )
));

$ini->merge($arr);

print_r($ini);

Works just fine in 1.3.3 .



24.8k

Hi Calin,

Thanks for testing, that's exaclty what I'm trying to do. Well almost: the process is the same, but I have parameters in my second Config object that don't exist in the first one.

Plus I should have mentioned it before, I'm using version 2.



51.2k

"but I have parameters in my second Config object " - does not matter. When you merg A + B if you have params that exists in A but not in B or viceversa thoes params will remain there.

I don't have any test env for 2.0 ...