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.lars...@telia.com> 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.
<?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
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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php