Get the object of Child type instead of parent from MongoDB
If I understand your issue correctly, you need PHP's built-in get_class()
or get_called_class()
functions.
Note : Objects themselves shouldn't forget which class they belong to, even if they are being returned by a function/method that only "knows" they are returning some instance of the superclass or one of its subclasses. So you should always be able to query which class an instance belongs to, via the get_class($instance)
function.