This is something that has been bugging me for a while and today I found a relatively easy solution that I thought I'd share as I couldn't seem to find any decent answer.
I have this code for my DB wrapper:
function find($id) {
//Fetch the results
//Put the results into an array
return (object) $results;
}
So I could do:
$result = DB::find(1);
echo $result->name; #=> Hello world
But I need to be able to assign methods to that new result. In this case to_json
json_encode?to_jsonfunction. It's about being able to implement functions that the $results variable can use.