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

Changed environment config loading from array_merge() to array_replace_recursive() #1225

Conversation

ChuckHeintzelman
Copy link
Contributor

Small change when loading environment specific configurations. Now the code below will merge the username/password into database connections array instead of replacing it entirely.

<?php
// my app/config/local/database.php
return array(
    'connections' => array(
        'mysql' => array(
            'username' => 'myname',
            'password' => 'mypass',
        ),
    ),
);

@taylorotwell
Copy link
Member

This is not the desired behavior and actually breaks config loading.

@taylorotwell taylorotwell reopened this May 7, 2013
@taylorotwell
Copy link
Member

Err, thought you said array_merge_recursive. Sorry, will look at this later.

@ChuckHeintzelman
Copy link
Contributor Author

Yes. array_merge_recursive() would break things. Here's a blog post illustrating the difference. http://jontai.me/blog/2011/12/array_merge_recursive-vs-array_replace_recursive/

@bencorlett
Copy link
Contributor

This is the exact same pull as #757 FYI @taylorotwell

@bencorlett
Copy link
Contributor

Having said that, I kinda like it and I do use it in my composite config package (which cascades config from the database).

@ChuckHeintzelman
Copy link
Contributor Author

Dang! I even searched for a previous pull request.

@taylorotwell
Copy link
Member

Yeah this seems to work well. I must have been making the same mistake in the previous pull request.

taylorotwell added a commit that referenced this pull request May 8, 2013
…-merging-recursively

Changed environment config loading from array_merge() to array_replace_recursive()
@taylorotwell taylorotwell merged commit ac47b1e into laravel:master May 8, 2013
@ChuckHeintzelman ChuckHeintzelman deleted the bug/environ-config-not-merging-recursively branch May 8, 2013 03:04
@ChuckHeintzelman
Copy link
Contributor Author

Add <?php as the first line of your app/config/local/database.php and that should fix it.

valorin added a commit to valorin/laravel-framework that referenced this pull request Aug 23, 2014
Normal configs were cascading with array_replace_recursive(), which
merged recursive arrays nicely, however Package configs were using
array_merge(), which only merged the top-level arrays. This is
inconsistent across the configuration handling, and is confusing for
users trying to override specific package configuration.

It looks like this fix was proposed in Issue laravel#757, but missed when the
Issue laravel#1225 was proposed, considered a duplicate, and eventually
merged.
gonzalom pushed a commit to Hydrane/tmp-laravel-framework that referenced this pull request Oct 12, 2023
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

Successfully merging this pull request may close these issues.

3 participants