codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.4k stars 1.9k forks source link

Bug: model() returns wrong instance #7312

Closed maniaba closed 1 year ago

maniaba commented 1 year ago

PHP Version

7.4

CodeIgniter4 Version

4.3.2

CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

Which operating systems have you tested for this bug?

Windows, Linux

Which server did you use?

apache

Database

MySQL (ver. 8.0.28)

What happened?

When I use the model() with different namespaces and the same class name it returns the wrong instance.

Steps to Reproduce


$mns1= model(\App\Models\Document::class, true);
$mns2= model(\Blog\Models\Document::class, true);

if ($mns2 instanceof \Blog\Models\Document) {
    echo "correct instance mns2";
} else {
    echo "wrong instance mns2";
}

Expected Output

Variable $mns2 should have an instance of \Blog\Models\Document but gets it as \App\Models\Document

Anything else?

No response

kenjis commented 1 year ago

No, this is intended. See https://codeigniter4.github.io/CodeIgniter4/concepts/factories.html#model-example and https://codeigniter4.github.io/CodeIgniter4/concepts/factories.html#model

maniaba commented 1 year ago

No, this is intended. See https://codeigniter4.github.io/CodeIgniter4/concepts/factories.html#model-example and https://codeigniter4.github.io/CodeIgniter4/concepts/factories.html#model

Thanks