Phalcon\Config triggers warning with integer keys
Consider the following example:
$config = new Phalcon\Config(array(
'404' => 'blah'
));
It triggers Warning: Phalcon\Config::__construct(): Property should be string (in ext/kernel/object.c, line 637)
For ArrayAccess it is perfectly fine to have keys as integers. In PHP it is a valid way to access them as properties using the following syntax: $config->{'404'}
Phalcon\Config doesn't allow numeric keys because the Phalcon\Config constructor is called recursively preserving numeric arrays as they are:
$config = new Phalcon\Config(array(
'list' => array(1, 2, 3, 4),
'other' => array(
'a' => 100,
'b' => false
)
));
Phalcon\Config Object
(
[list] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
[other] => Phalcon\Config Object
(
[a] => 100
[b] =>
)
)
OK, your answer is accepted. But it is just to remind you that PHP arrays are hash maps, Phalcon\Config implements ArrayAccess and so it is expected behaviour to be a map.
// example 1
// it is stated in documentation that Phalcon\Config walks through array recursiverly and converts
// children arrays to Phalcon\Config instances
// The following is expected:
$list = $config->list->toArray(); // convert Phalcon\Config to array outputs warning,
// $config->list is array already
// example 2
// normal behaviour for ArrayAccess cannot be used with numeric keys
if ( !isset($config->list[$key]) ) {
throw new \OutOfBoundsException('Unknown key [' . $key . ']');
}
I'm going to add a note in the docs explaining this behavior, thanks