I would think the following piece of code should work, but it doesn\'t (Edited: Now works in PHP 5.5+):
if (!empty($r->getError()))
As pointed out by others, it's a (weird) limitation of empty().
For most purproses, doing this is equal as calling empty, but this works:
if ($r->getError() != '')