Skip to content

Bug: [Factories] when there are classes with the same short name, only the first class is loaded #7694

@kenjis

Description

@kenjis

When there are classes with the same short name, and we try to load them with Factories by passing the full classname, only the first class is loaded.

There is no way to load the second class when specifying the full classname.

<?php

namespace App\Models;

use CodeIgniter\Model;

class Sample extends Model
{
    protected $table         = 'samples';
    protected $allowedFields = [];
}
<?php

namespace App\Models\Dir;

use CodeIgniter\Model;

class Sample extends Model
{
    protected $table         = 'dir_samples';
    protected $allowedFields = [];
}
<?php

namespace App\Controllers;

use App\Models\Dir\Sample as DirSample;
use App\Models\Sample;

class Home extends BaseController
{
    public function index()
    {
        $sample    = model(Sample::class);
        $dirSample = model(DirSample::class);

        var_dump($sample === $dirSample);
    }
}

The result is true.

Related #7684

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions