Rewrite code with PHP 5.3 BC support