You can even skip brackets:
$tags = array(); while ($tags[] = $stmt->fetchObject());
This code, of course, is slightly shorter than the more complex form:
$tags = array(); while ($tag = $stmt->fetchObject()) { $tags[] = $tag; }
However, which one is easier to read? You could say that both of them are completely obvious, and in fact I would agree with you. But which one is easier to maintain? To add a new statement like $tag->doSth(); into a shorter form, you need to completely rewrite it. In the latter, you simply add this statement.
source share