Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92036 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66998 invoked from network); 30 Mar 2016 22:10:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Mar 2016 22:10:34 -0000 Authentication-Results: pb1.pair.com header.from=bjorn.x.larsson@telia.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=bjorn.x.larsson@telia.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain telia.com from 81.236.60.155 cause and error) X-PHP-List-Original-Sender: bjorn.x.larsson@telia.com X-Host-Fingerprint: 81.236.60.155 v-smtpout2.han.skanova.net Received: from [81.236.60.155] ([81.236.60.155:52883] helo=v-smtpout2.han.skanova.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/A1-57520-6DE4CF65 for ; Wed, 30 Mar 2016 17:10:31 -0500 Received: from [192.168.7.7] ([195.198.188.252]) by cmsmtp with SMTP id lOJlaisG3GabYlOJmaMcoN; Thu, 31 Mar 2016 00:10:26 +0200 To: Joe Watkins , Dmitry Stogov References: <1458153695.3969.16.camel@kuechenschabe> <3F.70.02405.6803BE65@pb1.pair.com> <56F01545.8080008@gmail.com> <56F14572.701@gmail.com> <56F15EF5.80006@telia.com> <56F16023.1010002@gmail.com> Cc: Phil Sturgeon , Krakjo , PHP internals Message-ID: <56FC4ED6.6050701@telia.com> Date: Thu, 31 Mar 2016 00:10:30 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfAUDcqCZDBz5UjbgdfRy5ak9n9zOZ+pDs5GGCZIPnZN5xehsnT34+4PDKUAmeUQH5C93naXiX3vwEcHQw5jxsviVmHKd6It389vOHas0hAedvadJGoJX wMU/TWycD/2BDTHWL1hw2HBY2P+nBFyy2+0byVDYBz7Zg62RIEEtNzwXoS0I8sk++j33M1+LdOwVdLIBQ3cDtn8pQ8LaDsfuxqFCnbbj9RZ3dvMuSZc368ED UQH4Xn9bZ5YdTMJcevtqjw6b0YPKV00eDEJeRYBlswFoFHKjsX4aKi17jB2QRSkGm9OuPJETxy/+PttpgOlrfw== Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties From: bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_Larsson?=) Den 2016-03-30 kl. 05:16, skrev Joe Watkins: > Morning Dmitry, > >> 1) static typed properties are prohibited. why? > Feels like that's a separate feature, static properties are as good as > makes no difference, global variables. > > Instance properties, the engine has good control over their manipulation, > for static properties it doesn't, it's not impossible, but feels separate. Good that it's clarified in the RFC since one could easily believe that it's possible to set type for a static property. > >> 2) The handling of multiple properties in the same declaration statement > is inconsistent. > > This feels consistent to me .. in other languages where the type is > required, it makes sense to assume the type is implied. > > In a language where the type is optional, public int $foo, $bar; feels > ambiguous to me. Given that public is implied for all properties above there is a value in having the same rule for type. > >> 3) We already have nullable arguments without any special syntax. We > should reuse the similar approach for properties. > > Making properties implicitly nullable defeats the object of trying to > provide type safety. > > Null is never a valid value for a typed property, if it were, you would > never be sure of the type of variable you are getting, and would have to > litter your code with is_null checks. Maybe good to clarify difference towards default parameters? Anyway, in Hack following syntax passes: https://3v4l.org/3tUu9 > >> I think it might be better to implicitly initialize them according to > type (if default value is not provided): bool by false, int by 0, double by > 0.0, string by "" (interned), array by [] (immutable), objects by NULL > (always nullable). > > Definitely not, lying about the default value isn't a good idea. > > There are times when 0 is as valid as 1, or any other value for an int. > > If you have declared that you know the type of the property, and you write > code that accesses that property before there is any possible chance you > have set the property, that's a programming error. > > We should not hide that error with a default value, or by allowing the > engine to return null. Don't have a strong opinion on this one, can see both views. Maybe a bit affected by programming in Java recently, having a slightly more positive attitude towards default values ;-) Regards //Björn Larsson