On 11 March 2021 03:37:52 GMT, office.hamzaah...@gmail.com wrote:
><?php
>function get_nationality_string(int $country_code) : string | "unknown"
>{
>       return;
>};

If I understand you correctly, your idea is that the "return;" here would be 
treated automatically as "return 'unknown';" I think that's an interesting 
idea, although I can't immediately think of a situation where I'd use it.

My main concerns are with the syntax:

- Firstly, specific literals aren't currently allowed in return types, and 
allowing them would have other implications. Three exception is "false", which 
is allowed because of its common use as an error code, including in many 
internal functions.
- Secondly, it could be ambiguous which is intended to be the default value, if 
the return type was something like int|"yes"|"no"

Perhaps the default return value would need to be specified separately from the 
return type somehow?

Regards,
Hi Hamza,

Welcome to the list, and thanks for sharing this idea.

-- 
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to