Re: [RFC Discussion] Typed Properties
| From: | Björn Larsson | Date: | Sun, 17 Apr 2016 21:39:43 +0000 |
| Subject: | Re: [RFC Discussion] Typed Properties | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92390@lists.php.net to get a copy of this message | ||
Hi,
Den 2016-04-06 kl. 18:33, skrev Phil Sturgeon:
On Sat, Apr 2, 2016 at 3:10 PM, Björn Larsson <bjorn.x.larsson@telia.com> wrote: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örnGood evening,Den 2016-03-31 kl. 10:34, skrev Joe Watkins: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 allowMorning,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.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 rest my case here :-) Regards //BjörnAnyway, in Hack following syntax passes: https://3v4l.org/3tUu9Hack does not consider types implicitly nullable. <?hh 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 typethings.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<?hh 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 typethings.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 typeHHVM doesn't care about types ... we don't compare our type system to that ...