Function and class for PHP5