Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92390 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51041 invoked from network); 17 Apr 2016 21:39:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2016 21:39:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=bjorn.x.larsson@telia.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=bjorn.x.larsson@telia.com; 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:48918] helo=v-smtpout2.han.skanova.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B9/0E-32052-E9204175 for ; Sun, 17 Apr 2016 17:39:44 -0400 Received: from [192.168.7.7] ([195.198.188.252]) by cmsmtp with SMTP id ruPrah68WqtwZruPramSeD; Sun, 17 Apr 2016 23:39:40 +0200 To: Phil Sturgeon References: <56F14572.701@gmail.com> <56F15EF5.80006@telia.com> <56F16023.1010002@gmail.com> <56FC4ED6.6050701@telia.com> <57001915.3030407@telia.com> Cc: Joe Watkins , Dmitry Stogov , Krakjo , PHP internals Message-ID: <5714029F.603@telia.com> Date: Sun, 17 Apr 2016 23:39:43 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfE+BwKCXBmci2BQ+lzxA73aqmx3Woze9Mf0DgXB4DHBgiA9r0BJGAnqP3caZykiQkoMK/W3EBYUwYy94YRXV3+CNgkaifvG0wJeQO+bPK8wIgWKpeNck V2iaxjytDk4naMFDmy0RnDhbmtqMtMG/sRNnNkm5GvdhCk8PuV26Ht/J7IkGzDb9purExkstknWztpFFPsuoJDmDB01gMeeuYvWM3hdK+MSCuDAOuWTtSwu5 iHDNl8DAEE6x335lrscgNmjwLD+IT8j1bCP8nJck5Q8cKqaIvGQEzRNIUVxUap3Y75v4Uac9NMWp+fDuh9msEA== Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties From: bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_Larsson?=) Hi, Den 2016-04-06 kl. 18:33, skrev Phil Sturgeon: > On Sat, Apr 2, 2016 at 3:10 PM, Björn Larsson wrote: >> Good evening,Den 2016-03-31 kl. 10:34, skrev Joe Watkins: >>> Morning, >>> >>>> Given that public is implied for all properties above there >>>> is a value in having the same rule for type. >>> public $bar, int $foo; >>> >>> What does this mean? >>> >>> If it's not an error, what does this mean ? >>> >>> public $bar, int $foo, $qux; >>> >>> If it's an error, why is it an error ? >>> >>> Both of these examples are just as ambiguous as >>> >>> public int $foo, $bar, $qux; >>> >>> Access modifiers are assumed to apply to all declarations in a group, >>> because that's what grouping is actually for. >>> >>> We don't need to make grouping about types, we need to make type >>> declarations unambiguous. >> I think by issuing an error on the two first one we make the >> third one unambiguous. It also makes it a bit easier to explain >> and remember rules for visibility and type keywords before >> a list of properties, i.e. they are close to the same. >> >> Having the public keyword optional would be nice, but then >> as you say it should be the same for untyped properties. >> >>>> Anyway, in Hack following syntax passes: https://3v4l.org/3tUu9 >>> Hack does not consider types implicitly nullable. >>> >>> >> class Foo { >>> public int $int = null; >>> public stdClass $std = null; >>> } >>> >>> things.php:3:10,12: Wrong type hint (Typing[4110]) >>> things.php:3:10,12: This is an int >>> things.php:3:21,24: It is incompatible with a nullable type >>> things.php:4:10,17: Wrong type hint (Typing[4110]) >>> things.php:4:10,17: This is an object of type stdClass >>> things.php:4:26,29: It is incompatible with a nullable type >>> >>> >> function foo(int $int = null, stdClass $std = null) {} >>> >>> things.php:2:18,21: Wrong type hint (Typing[4110]) >>> things.php:2:14,16: This is an int >>> things.php:2:25,28: It is incompatible with a nullable type >>> things.php:2:40,43: Wrong type hint (Typing[4110]) >>> things.php:2:31,38: This is an object of type stdClass >>> things.php:2:47,50: It is incompatible with a nullable type >>> >>> HHVM doesn't care about types ... we don't compare our type system to that >>> ... >> I rest my case here :-) >> >> Regards //Björn >> > > We polled pretty hard and had a bunch of discussions about how > multiple declarations should work, and ended up siding with Zeev and > Larry, and all those others saying that type declarations should work > for all just as visibility does currently: > > > public int $foo, $bar; > > $bar here will be int. > > Trying to specify another type will resolve in an error. RFC is > updated to match. > > We have a few more implementation tweaks to make, then it's off to the > races with this one. > Have you come to any conclusion if one should allow null as a default value in a similar way like for function arguments? Secondly, would it be of interest to allow initiation of multiple variables of same type in one go? I tested on: https://3v4l.org/rRRqf Regards //Björn