rewriting function to use callback in newest version of php