Re: [RFC Discussion] Typed Properties

From: Date: Sat, 02 Apr 2016 19:10:13 +0000
Subject: Re: [RFC Discussion] Typed Properties
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  Groups: php.internals 
Request: Send a blank email to internals+get-92072@lists.php.net to get a copy of this message
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. <?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 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 <?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 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

« previous php.internals (#92072) next »