On 23/02/2021 18:41, Albert Casademont wrote:
Sure, it's not a big deal having to write the ": null" but it doesn't add
any value
On the contrary, it adds an important piece of information: that the
default value is "null", rather than "false", or "0", or "new EmptyValue()".
For instance, it doesn't seem at all obvious to me that this code should
produce a null:
$items = [];
$itemCount = $items ? count($items);
I might be more convinced that "null" is the "natural" value if the
left-hand operand was only checked against null, not "falsiness": in
that case, you can read it as "if it's null, leave it alone". I'd still
be inclined towards "too specific to use up more syntax", though.
A better example would creating UUID VO's from string|null
input, there's little room for a default here.
I'm not quite sure what process you're describing, but any of the
following seem equally reasonable:
$nullableUuid = is_null($input) ? UUID::for($input) : null;
$maybeNilUuid = is_null($input) ? UUID::for($input) : UUID:nilValue();
$definitelyUuid = is_null($input) ? UUID::for($input) : UUID:random();
Syntax for skipping the is_null/isset on the left would be higher up my
wish list than syntax for skipping the :null on the right.
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php