Safely cast values to int, float, or string in PHP