Hello Tom,
with default return value I mean to return a certain value if nothing else is returned (similar to
method parameters with a default value).
example 1:
declare(strict_types=0);
function my_strpos(string $haystack, string $needle): int = false {
return 42; // return 42
return false; // return false
return true; // return 1
return; // return false
}
example 2:
declare(strict_types=1);
function my_strpos(string $haystack, string $needle): int = false {
return 42; // return 42
return false; // return false
return true; // fatal error
return; // return false
}
Regards
Thomas
[email protected] wrote on 21.04.2016 15:05:
> Hi Thomas,
>
>
> What is a default return declaration? Is this for branches within the function
> that do not lead to a return statement?
>
>
> Tom
>
>
>
>
>
> From: Thomas Bley
> Sent: Wednesday, April 20, 2016 12:53 PM
> To: [email protected], [email protected], [email protected]
> Cc: [email protected], [email protected]
>
>
>
>
>
> What do you think about default return values?
>
> e.g.
>
> function foo(): db_result = null {
> }
>
> function canLogin(): bool = false {
> }