Skip to content

Bug: config() can't load Config file in a module if there is a Config file with the same name #5356

@kenjis

Description

@kenjis

PHP Version

8.0

CodeIgniter4 Version

develop (0aa542b)

Which operating systems have you tested for this bug?

macOS

Which server did you use?

cli-server (PHP built-in webserver)

Database

No response

What happened?

config() can't load Config file in a module if there is a Config file with the same name.

Steps to Reproduce

Configure 'Acme\Blog namespace:

--- a/app/Config/Autoload.php
+++ b/app/Config/Autoload.php
@@ -43,6 +43,7 @@ class Autoload extends AutoloadConfig
     public $psr4 = [
         APP_NAMESPACE => APPPATH, // For custom app namespace
         'Config'      => APPPATH . 'Config',
+        'Acme\Blog'   => ROOTPATH . 'acme/Blog',
     ];
 
     /**

Create acme/Blog/Config/Blog.php:

<?php

namespace Acme\Blog\Config;

use CodeIgniter\Config\BaseConfig;

class Blog extends BaseConfig
{
    public $siteName  = 'My Great Site';
    public $siteEmail = 'webmaster@example.com';
}

Create app/Config/Blog.php:

<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Blog extends BaseConfig
{
    public $siteName  = 'app/Config/Blog';
    public $siteEmail = 'webmaster@example.com';
}

Create acme/Blog/Config/Routes.php:

<?php

$routes->group('blog', ['namespace' => 'Acme\Blog\Controllers'], function ($routes) {
    $routes->get('/', 'Blog::index');
});

Create acme/Blog/Controllers/Blog.php:

<?php
namespace Acme\Blog\Controllers;

use App\Controllers\BaseController;

class Blog extends BaseController
{
    public function index()
    {
        $config = config(\Acme\Blog\Config\Blog::class);
        echo $config->siteName;
    }
}

Run php spark serve.

Navigate to http://localhost:8080/blog

You see app/Config/Blog.

Expected Output

My Great Site

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions