foreach ($item as $key => $value) { $retval[$key] = self::from($value); } return $retval; } // same as our first example private static function trimFromTraversable(Traversable $item) : array { $retval = []; foreach ($item as $key => $value) { $retval[$key] = self::from($value); } return $retval; } // same as our first example public static function trimFromString(string $item) : string { // PHP will coerce into a string for us return trim($item); } // same as our first example private static function nothingMatchesTheInputType($item) { // we don't know how to process $item, so let's just // send back exactly what we received return $item; } } // only happens when we're first loaded TrimWhitespace::initDispatchTable();