Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config::get changed return value #1068

Closed
viktoras25 opened this issue Aug 12, 2013 · 5 comments
Closed

Config::get changed return value #1068

viktoras25 opened this issue Aug 12, 2013 · 5 comments

Comments

@viktoras25
Copy link
Contributor

Let's take a sample config:

$config = new \Phalcon\Config(array("test" => array(1, 2, 3)));
die(var_dump($config->get("test")));

In 1.2.0 it produces an array:

array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

In 1.3.0 it produces an object:

object(Phalcon\Config)#2 (3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

This is inconsistent, and it's not stated in changelog.

@ghost
Copy link

ghost commented Aug 12, 2013

It is mentioned — in the past Phalcon\Config did not support numeric properties and therefore arrays with numeric indices had to be treated as arrays and could not be converted to Phalcon\Config (see, for example, #696 for the discussion). Thus, if you had an array with numeric properties, you could not consistently use -> to traverse the config — you had to check whether the returned item is array and if so, use [] instead. Not to mention that numeric indices caused issues with merge()

In #842 this has been fixed and arrays with numeric keys are converted to Phalcon\Config objects.

But as far as I understand, you can use this both in 1.2.0 and 1.3.0:

$config->get('test')[1];

or (in 1.3.0)

$config->test->{1};

In other words, Phalcon\Config tries to mimic the plain array and in most cases you should not see any difference.

@viktoras25
Copy link
Contributor Author

Oh, I see now what "Phalcon\Config now support numeric properties as well" means. Thank you for the explanation. I think this should be stated in config.rst, because it's a little bit tricky and unobvious thing unless you track this repository issues.

@ghost
Copy link

ghost commented Aug 12, 2013

What is config.rst?

@viktoras25
Copy link
Contributor Author

@ghost
Copy link

ghost commented Aug 15, 2013

Could you please file a bug report here: https://github.com/phalcon/docs/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant