laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.52k stars 11.02k forks source link

Using a numeric value as a key for a database connection in config file will result in it not being loaded with that name. #52898

Closed ItsClassified closed 1 month ago

ItsClassified commented 1 month ago

Laravel Version

11.23.5

PHP Version

8.3.11

Database Driver & Version

MySQL

Description

When using numeric values in the database.php config file Laravel will disregard the names and load them starting from 0, and increasing for each connection after that with a numeric value as name.

@ollieread found that commenting out row 127 in the following file makes it load in again: https://github.com/laravel/framework/blob/11.x/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php#L103

The issue appears to be on L103 using array_merge

Steps To Reproduce

Change a connection name to a numeric string, for example: '12345' and try to access it using DB::connection.

ollieread commented 1 month ago

Just to add a bit more, the issue is when it tries to merge database.connections, as PHPs array_merge() is doing some annoying type juggling and assuming keys that are numeric strings, are, in fact, just numeric, and it's resetting those keys.