I was wondering if the following is possible. We have a class that is design to used chained methods.
$CarClass = $CarConnection->models->count();
In the above example we are counting the models. However, want to do it dynamically. So for instance:
$CountArray = array('models','brands','countries');
foreach($CountArray AS $key => $value){
$CarData[$value] = $CarConnection->$value->count();
}
However, this outputs an error: "Call to a member function count() on a non-object in" While i'm pretty sure the count exists as the earlier mention function is working.
Some googling led to add brackets { } but that doesn't work either.
$CarData[$value] = $CarConnection->{$value}->count();
Any one a solution?
Kind regards,
Peter
$CarConnectionhas themodel,brandsandcountriesproperties and they are objects that expose thecount()method. The error message say you are callingcount()on a value that is not an object. It may beNULLor something else (array, string, integer etc.)