/**
  * Cast a value to string.
  *
  * @static
  *
  * @param mixed $value       Value to cast.
  * @param bool  $array2null  (Optional) Whether to return null for an array or to cast the
  *                           individual values within the array to the chosen type.
  * @param bool  $allow_empty (Optional) Whether to allow empty strings/arrays/objects.
  *
  * @return string|array|null
  */
 function _string($value, $array2null = true, $allow_empty = true)
 {
     if (is_string($value) && ($value !== '' || $allow_empty === true)) {
         return $value;
     } else {
         if (is_int($value) || is_float($value)) {
             return strval($value);
         } else {
             if ($array2null === false && is_array($value)) {
                 return CastToType::recurse($value, '_string', $allow_empty);
             } else {
                 if (is_object($value) && get_parent_class($value) === 'SplType') {
                     if ((string) $value == $value) {
                         return (string) $value;
                     } else {
                         return null;
                     }
                 } else {
                     if (is_object($value) && method_exists($value, '__toString')) {
                         return (string) $value;
                     }
                 }
             }
         }
     }
     return null;
 }