To keep your interface and inheritance hand in hand, I think it is better to separate your logic:
UserRepository->getVehicles("sedan");
Or you can utilize method-chaining:
UserRepository->getVehicles()->sedan;
In the above code, getVehicles()
, returns a collection object which has NOT a property named sedan
.
You have to use php __get()
to do the operation.
Why then I do this? Because if you were able to fetch the cars by type though a property (remember properties are not functions, there is no execution), then it literally means that you have fetches all types and have them ready:
WRONG WAY AND MEMORY-KILLER APPROACH is that you fetch all of the user's car and put each type in its associated property.
Better way is returning an object, the object then is shipped with a function __get()
to be invoked on each property retrieval:
$object->sedan;
sedan
does not exist, so you have already predicted that:
function __get($param)
{
$this->__getByType($param);
}
Though I prefer my very first suggestion.