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

\Phalcon\Config Bug - i cant merge or use several config files with same variable names e.g $config both config.php and in main

Phalcon version 2.1.0b Hello, i cant merge several config files with same variable name e.g $config in main index.php file

A.config.php

<?php

$config = []; // without this type, we getting
**Fatal error: Uncaught exception 'Exception' with message 'The argument is not initialized or iterable()' in phalcon/config.zep on line 62**

$config['x'] = 'x';

return $config;
?>

B.config.php

<?php

$config = [];

$config['x'] = 'y';

return $config;

index.php

//same variable names ->>>> $config <<<--- in config.php and index.php on $config object

<?php

$config = new Phalcon\Config(require 'A.config.php');

$config2 = new Phalcon\Config(require 'B.config.php');

print_r($config,$config2);
?>
<pre>Array 
(
    [x] => y
)
</pre><pre>Phalcon\Config Object
(
    [x] => y
)
</pre>

NOW merging and getting FATAL ERROR

<?php

$config = new Phalcon\Config(require 'A.config.php');
$config2 = new Phalcon\Config(require 'B.config.php');

$config->merge($config2);// Fatal error: Call to a member function merge() on array in
?>

//AND LAST NOW OK AND WORKING

<?php

$configXXXXX = new Phalcon\Config(require 'A.config.php');

$configYYYYYY = new Phalcon\Config(require 'B.config.php');

$configXXXXX ->merge($configYYYYYY );//NOW OK
?>


2.3k

Thanks :)

Put an empty line above each code section to get the PHP highlighting to work. Just edit the post and insert a newline right before every section.



2.3k
edited Dec '15

Phalcon version 2.1.0b

Still not working

return $config;
***********
$config = new Config([]);
$config->merge($config1);
$config->merge($config2);

ERROR Fatal error: Call to a member function merge() on array


and Working


return $config;
***********

$otherWARIABLE = new Config([]);
$otherWARIABLE->merge($config1);
$otherWARIABLE->merge($config2);

other bug ??


return $config; //local var
***********

$otherWARIABLE = new Config([]);
$otherWARIABLE->merge($config1);
$otherWARIABLE->merge($config2);

// $config becomes global var ??
print_r($config)  // this variable comes from CONFIG FILE - NOT A BUG????