Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92611 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17333 invoked from network); 21 Apr 2016 21:47:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Apr 2016 21:47:25 -0000 Authentication-Results: pb1.pair.com header.from=mails@thomasbley.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=mails@thomasbley.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain thomasbley.de from 85.13.128.151 cause and error) X-PHP-List-Original-Sender: mails@thomasbley.de X-Host-Fingerprint: 85.13.128.151 dd1730.kasserver.com Received: from [85.13.128.151] ([85.13.128.151:57888] helo=dd1730.kasserver.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/57-14036-B6A49175 for ; Thu, 21 Apr 2016 17:47:24 -0400 Received: from dd1730.kasserver.com (dd0803.kasserver.com [85.13.146.34]) by dd1730.kasserver.com (Postfix) with ESMTPSA id D067B1A8068E; Thu, 21 Apr 2016 23:47:20 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-SenderIP: 109.46.255.65 User-Agent: ALL-INKL Webmail 2.11 In-Reply-To: <57192AEE.2000702@fleshgrinder.com> References: <570F4BB4.6020709@zend.com> <57112225.6020905@thefsb.org> <57119B5E.6070205@thefsb.org> <20160420165307.9C86E1A83D08@dd1730.kasserver.com> <31.BF.14036.A61D8175@pb1.pair.com> <20160421163334.368CF1A80188@dd1730.kasserver.com><57192AEE.2000702@fleshgrinder.com> To: guilhermeblanco@gmail.com, cornelius.howl@gmail.com, dmitry@zend.com, fsb@thefsb.org, internals@lists.php.net Cc: internals@lists.php.net Message-ID: <20160421214720.D067B1A8068E@dd1730.kasserver.com> Date: Thu, 21 Apr 2016 23:47:20 +0200 (CEST) Subject: Re: [PHP-DEV] [RFC] Nullable Types From: mails@thomasbley.de ("Thomas Bley") > Note that the same /would/ be possible with union types if given precedence: > > function fn(): int|false {} false is currently not supported in the union_types rfc. Regards Thomas Fleshgrinder wrote on 21.04.2016 21:33: > 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 > >