Skip to content

Commit da28aab

Browse files
authored
[11.x] Fix issue where $name variable in non base config file becomes it's key (#52738)
* Prepare example where the `$name` variable becomes the key of the config * Require path in isolation * Use arrow function
1 parent e2196b1 commit da28aab

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function loadConfigurationFiles(Application $app, RepositoryContract $
9393
*/
9494
protected function loadConfigurationFile(RepositoryContract $repository, $name, $path, array $base)
9595
{
96-
$config = require $path;
96+
$config = (fn () => require $path)();
9797

9898
if (isset($base[$name])) {
9999
$config = array_merge($base[$name], $config);

tests/Foundation/Bootstrap/LoadConfigurationTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,15 @@ public function testDontLoadBaseConfiguration()
2626

2727
$this->assertNull($app['config']['app.name']);
2828
}
29+
30+
public function testLoadsConfigurationInIsolation()
31+
{
32+
$app = new Application(__DIR__.'/../fixtures');
33+
$app->useConfigPath(__DIR__.'/../fixtures/config');
34+
35+
(new LoadConfiguration())->bootstrap($app);
36+
37+
$this->assertNull($app['config']['bar.foo']);
38+
$this->assertSame('bar', $app['config']['custom.foo']);
39+
}
2940
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$name = 'bar';
4+
5+
return [
6+
'foo' => $name,
7+
];

0 commit comments

Comments
 (0)