I create parent class for my models, it look like this
class Model {
protected static $cache = [];
public static function load($id)
{
return static::$cache[$id];
}
public static function findById($id)
{
$model = static::find($id);
static::$cache[$id] = model;
return model;
}
...
}
And i have two child class, examples
class A extend Model {}
class B extend Model {}
then, i write
A::findById(1);
B::findById(1);
$a = A::load(1);
$b = B::load(1);
I think type of class $b is class B, but not, it is class A, because function "load" use static cache and load result from function A::findById(1). Why?