Fix end() in php5.3