Hi Thomas,

Sorry for the delay. I was traveling last week.

By convention `return;` in PHP is an early return for a function that
returns nothing at all. I think it can be confusing when reading a
function to look at a `return;` line and have to remember to look
elsewhere to discover what that means. And it can mean something different
in every function.

I prefer to write functions that return only the declared type. In some
cases I need to write functions that return only the declared type or
null. That's the limit of what I think PHP 7.1 should provide.

Hence, for me this has no attraction but it does introduce new ways to
write bugs. So I am not enthusiastic.

Tom


On 4/21/16, 12:33 PM, "Thomas Bley" <ma...@thomasbley.de> 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
>}
>
>Regards
>Thomas
>
>
>f...@thefsb.org 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: guilhermebla...@gmail.com, cornelius.h...@gmail.com, dmi...@zend.com
>> Cc: f...@thefsb.org, internals@lists.php.net
>> 
>> 
>> 
>> 
>> 
>> What do you think about default return values?
>> 
>> e.g.
>> 
>> function foo(): db_result = null {
>> }
>> 
>> function canLogin(): bool = false {
>> }
>



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

Reply via email to