On 4/21/2016 6:33 PM, Thomas Bley wrote:
> 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
> }
>
I definitely do not like the equal sign in there because it goes against
all my mathematical knowledge; an int is false?!?
Note that the same /would/ be possible with union types if given precedence:
function fn(): int|false {}
That being said, it is way too magic! A return without an argument is
*void* and has to result in a `TypeError`. Really, start to think about
the types as /checked annotations/ ...
/**
* @return int|false
*/
function fn() {}
function fn(): int|false {}
... are equivalent and the former does not suddenly return *false* on
its own and hell it shouldn't.
--
Richard "Fleshgrinder" Fussenegger
signature.asc
Description: OpenPGP digital signature
