Firstly, a bit of humorous wordplay: witch = itch = burn; "She's a witch! BURN HER!" I think you meant "which" in this context. Now that is out of my system, on to the review :)
Why are you extending the stdClass? This is the class reserved for typecasting variables as classes. It is just a wrapper that has no benefits of being extended from. If you are just trying to create a normal class then just drop the extends stdClass
bit. Its unnecessary.
Additionally, where did properties $first_name
and $last_name
come from? They were not declared. This means they either are coming from the parent class, which is impossible as the stdClass is empty, or they are defaulting to the public scope. If you were extending another class and that property was defined there, this would be fine, but default properties are bad. Besides, I have heard rumors that it will be deprecated soon, so prepare for the worst and just manually define their scope.
class User {
public
$first_name,
$last_name
;
//etc...
}
What is the point of the Post
class? Just to declare the $author
property? This is unnecessary, especially for a full fledged class. The only time I could foresee something like this being ok is if it were part of an interface or abstract class, but then it should also declare the expected methods as well.
Why is your database class completely static? I understand adopting a singleton pattern to ensure only one connection can be made, but after that you should be able to use the rest of your class like normal. Instead you are calling it statically everywhere. This is what you should be able to do with the singleton pattern. Notice how you only have to get the instance once.
$db = DB::getInstance();
$db->setFetchTableNames( 1 );
$sql = $db->select(//etc...
Why are you looping over the same information twice? If you find yourself looping over something in order to create an array so that you can loop over it again, don't. Just do it all the first time.
while( $post = $stmt->fetchInto( new Post(), 'p' ) ) {
$post->author = $stmt->fetchIntoFromLastRow( new User(), 'u' );
echo $post->author->getName();
}
Now, I can't really help you much more because you've not posted all of your code, just examples. I can't review your class except in the abstract. If you want a more complete review, you should follow the FAQ and post all related code. For instance, you are asking about your database wrapper, but all you have posted are a couple of slightly related container classes and example usages. Where's the actually database wrapper?