Skip to content

Weird behaviour of Connection class #18209

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

Closed
vikkio88 opened this issue Mar 4, 2017 · 4 comments
Closed

Weird behaviour of Connection class #18209

vikkio88 opened this issue Mar 4, 2017 · 4 comments

Comments

@vikkio88
Copy link
Contributor

vikkio88 commented Mar 4, 2017

  • Laravel Version: >4.x.x
  • PHP Version: >5.6
  • Database Driver & Version: does not matter

Description:

I am using the standalone Eloquent in one small project, and to re-use the same db connection configuration I used Connection::getConfig($option) method (https://github.com/laravel/framework/blob/5.4/src/Illuminate/Database/Connection.php#L963), passing a void instead of the $option.
And it returned the whole config array (which is what I originally wanted to be honest), but if you put the errors on you will get some warnings related to the call this object does to Arr::get() method, since $key is null.
Is this a wanted behaviour?
I was thinking to open a PR to change this piece of code to be a avoid throwing errors, something like:

    public function getConfig($option = null)
    {
       if (empty($option)){
           return $this->config;
       }
        return Arr::get($this->config, $option);
    }

Can I do that? Or would be better to create another getter

    public function getConfigs()
    {
        return $this->config;
    }

Steps To Reproduce:

Just call this method without parameter

$dbConfig = Capsule::connection()->getConfig();

$dbConfig will have your config array, but some errors related to the way Arr::get handles the null value of key will be thrown

@ntzm
Copy link
Contributor

ntzm commented Mar 10, 2017

What warnings are you getting? If you are passing null to getConfig it shouldn't even get to Arr::get

@vikkio88
Copy link
Contributor Author

I am getting "wrong argument number" warning not passing any, but I get the whole configuration, or if I pass null I don't get the warning and I still get all the configuration array.
I was just wondering if this behaviour was normal or not, it is useful for me, but probably for consistency would be better to create a getConfigs() method?

@themsaid
Copy link
Member

Sorry but Laravel 4 is not supported anymore, please use the forums to post such questions.

@vikkio88
Copy link
Contributor Author

@themsaid wasnt really about laravel 4, I am using 5.3, I was reporting that this weird behaviour is happening since laravel 4.*

taylorotwell pushed a commit that referenced this issue Mar 15, 2017
* #18209
implementing fix proposed on the issue

* Update Connection.php
symfony-splitter pushed a commit to illuminate/database that referenced this issue Mar 15, 2017
* laravel/framework#18209
implementing fix proposed on the issue

* Update Connection.php
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

3 participants