Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92558 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76898 invoked from network); 20 Apr 2016 16:53:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2016 16:53:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=mails@thomasbley.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=mails@thomasbley.de; 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:34801] helo=dd1730.kasserver.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1C/B0-14036-6F3B7175 for ; Wed, 20 Apr 2016 12:53:11 -0400 Received: from dd1730.kasserver.com (dd0803.kasserver.com [85.13.146.34]) by dd1730.kasserver.com (Postfix) with ESMTPSA id 9C86E1A83D08; Wed, 20 Apr 2016 18:53:07 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-SenderIP: 217.240.29.251 User-Agent: ALL-INKL Webmail 2.11 In-Reply-To: References: <570F4BB4.6020709@zend.com> <57112225.6020905@thefsb.org> <57119B5E.6070205@thefsb.org> , To: guilhermeblanco@gmail.com, cornelius.howl@gmail.com, dmitry@zend.com Cc: fsb@thefsb.org, internals@lists.php.net Message-ID: <20160420165307.9C86E1A83D08@dd1730.kasserver.com> Date: Wed, 20 Apr 2016 18:53:07 +0200 (CEST) Subject: Re: [PHP-DEV] [RFC] Nullable Types From: mails@thomasbley.de ("Thomas Bley") What do you think about default return values? e.g. function foo(): db_result = null { } function canLogin(): bool = false { } Regards Thomas Dmitry Stogov wrote on 20.04.2016 18:13: > What we really miss now, is an ability to define nullable return types. > > > https://wiki.php.net/rfc/nullable_return_types > > > I don't care about the same notations for arguments (and everything else), > because we already may use NULL default value. > > However usage of "?" for arguments also may make sense. Someone may like this, > someone not. > > > Thanks. Dmitry. > > ________________________________ > From: guilhermeblanco@gmail.com > Sent: Wednesday, April 20, 2016 18:05 > To: Lin Yo-An > Cc: Dmitry Stogov; Tom Worster; internals > Subject: Re: [PHP-DEV] [RFC] Nullable Types > > I read the RFC and I want to highlight why I'll vote -1 on it even before it > goes to voting. > > IMHO, it looks backwards to what the language is progressing. The introduction > of nullable type hint as a separate notation than a simple type hint makes it > *very* hard to implement typed properties, factory methods and constructor > verifications. > > Dmitry is even involved in the discussion of having IS_UNDEF until constructor > ends, then enforcing type hinting at the end of constructor to trigger > potential invalid instance state. It created a mess in the internal structure > by creating a 3-state value: uninitialized, absent of value (null) and assigned > value. All this problem would be solved by merging null into accepted value. > So far the proposed solution there to take a wrong assumption to assume a > default value based on type defined (like int = 0, string = '', etc), which are > all potential valid values, leading to unpredictable behavior if a develop > misses to assign a value to that property. > > Sure, people will say that now PHP will require a NullPointerException, PHP is > turning into Java, or that I don't know what I'm talking about because they > coded for Amiga and I don't (yes, I've seen that already in this mailing list). > But the fact is that keeping control of 3-state flags are hard to maintain. > > Constructor verifications is actually a completely different subject that > shouldn't be considered as part of typed properties, but for final properties > (or whoever other keyword someone think is smarter because *reasons*). It's bad > to bring this already to typed properties, specially because of its runtime > performance impact. > > Now let's say we move forward with nullable type hint, ignore everything what I > said and move forward. Congratulations, we just created a language > inconsistency. Example: > > function foo(Bar $bar = null); > > Why now I have 2 ways to define a nullable value? Shouldn't this be changed > into this: > > function foo(?Bar $bar); > > But of course, changing this would be a BC break and should be left for > *reasons*. But accepting the absence of value (null) as a valid value, it would > address the language inconsistency (the current support would be kept, so no BC > break), and would solve a huge mess that typed properties patch currently needs > to solve. Ah, and we don't continue into this path of madness where same thing > have 144 different ways in different areas to be defined. > > > Regards, > > On Mon, Apr 18, 2016 at 12:24 PM, Lin Yo-An > > wrote: > On Mon, Apr 18, 2016 at 4:59 PM, Dmitry Stogov > > wrote: > >> The grammar is taken from HHVM. >> Using any other would make more mess. >> > I agree > > > > -- > Guilherme Blanco > Lead Architect at E-Block >