This is something that's been bugging me with PHP for a while now and I still can't figure out how I would do it. Basically at the moment for my SQL class I'm dumping the results in an array and converting them to an object to give something like this:
$first_post = $Post->find(1);
(I've also been trying to get the syntax to look like: $Post::find(1); but that's a different and purely aesthetic issue altogether)
and then you can use first_post like so:
$first_post->title;
This is done by just converting the contents of $post->find(1)
to an object like so:
$first_post = (object) array("title" => "blah");
and I know that instantiates a new STDClass but I can't figure out how to bind methods to that new instance of STDClass. It's mainly so I can do stuff like:
$posts = $Post->all();
$last_post = $posts->last();
$specific = $posts->find("name" => "hello");
Any ideas how I would get PHP to do something like this?