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
Implementing ArrayAccess for Config #2391
Conversation
…guide_src accordingly Signed-off-by: RJ garcia <rj@bighead.net>
|
||
public function offsetExists($key) | ||
{ | ||
return isset($this->config[$key]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything that checks for array offsets should use array_key_exists()
instead of isset()
, due to false negatives from NULL values.
Related: the config class' item()
method has this problem, too, which should be fixed.
CI's styleguide doesn't accept camelCase. And of what use is this anyway? |
@narfbg, when implementing ArrayAccess, those methods, which are written in camelCase in the documentation, need to be implemented. I'm split on whether this should be included in CI. It sets a bad precedence for configuration for other areas of CI, such as individual libraries, etc. I think it should remain in a fork or overloaded Config library, but then again, there's no way to implement it in a class extension anyway.... hmmm. |
|
||
public function offsetExists($key) | ||
{ | ||
return array_key_exists($this->config[$key]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing second parameter.
@TheDigitalOrchard Sure you can. class MY_Config extends CI_Config implements ArrayAccess {} |
By the way, shouldn't |
Um, sorry for the period of silence, but I'm fine if this feature doesn't get implemented; however, it's nice syntactic sugar, doesn't affect runtime performance, doesn't break old code, and doesn't affect people who don't want to use that feature, and it's a pretty neat feature for people who want it. If that argument doesn't sound that great to everyone else, then I'm totally fine with closing the ticket. |
If it is to be accepted, you still need to make a couple updates to make it ready to merge. |
Signed-off-by: RJ garcia <rj@bighead.net>
I'm still having a hard time understanding this and the included documentation changes doesn't make it any clearer. If I can't understand the benefits, how could a newbie reading the docs do? |
This feature is primarily for syntactic sugar. We can update the documentation to be clearer, but it's just a simpler and more concise way of accessing the main config array. It doesn't affect runtime performance, and it's the same time complexity as using |
OK, consider me a complete newbie and answer to these questions:
|
FYI, I proposed for |
$str = "This string is {$this->config['str_state']}"; vs: $str = "This string is ".$this->config->item('str_state'); How often that feature would be used in this way is to be established. |
Basically, there's no new value or feature added, it just gives users another option for how to access / define config items. It's possible that some people would prefer array notation; this would give them the option. |
@cryode and @TheDigitalOrchard is correct. It's pretty much syntactic sugar, it doesn't affect runtime performance, using it is just efficient as |
@ragboyjr - it appears you added a commit with totally unrelated changes from this pull request. Was that a mistake? |
@TheDigitalOrchard, I'm pretty sure that Merge was because I was just updating my CI repo to the latest in development |
This syntax allows for less verbose accessing of config items. The only issue I see is that
offsetGet
will returnNULL
if it doesn't exist whereas$this->config->item('item');
will return false.