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