On Sun, 10 Jan 2021 at 21:28, Larry Garfield <la...@garfieldtech.com> wrote: > > > making a valueOrDefault() method unnecessary. > > $order = SortOrder::tryFrom($input) ?? SortOrder::Asc; >
tbh, I would prefer a valueOrDefault() method, partly because it's what I'm used to in my own code* but also I think it would be easier to explain to a junior, or for a junior to remember. cheers Dan Ack *interface VarMap { /** * @param string $name * @return mixed * @throws \VarMap\Exception\VariableMissingException */ public function get(string $name); /** * @param string $name * @return bool */ public function has(string $name) : bool; /** * @param string $name * @param mixed $defaultValue * @return mixed */ public function getWithDefault(string $name, $defaultValue); } -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php