Andrea Faulds wrote:
> For parameters, the type is of the thing itself:
>
> function foo(Foo $foo, Bar $bar);
>
> Here, $foo is of the type Foo, and $bar is of the type Bar.
>
> But say if we were to add return types like this:
>
> function FooBar qux();
>
> The type of qux isn’t a FooBar, it’s a function (more accurately, an
> argument-less, return-anything function). FooBar isn’t what qux is, it’s not
> qux’s type, merely what it returns. In a sense, I’d say there’s already a
> type here: `function`.
>
> Compare it to this:
>
> function qux(): FooBar;
>
> FooBar is what qux returns, `function` is what qux is.
>
> If we were to hypothetically add typed properties with the same syntax Hack
> has, they’d look like this:
>
> public Foo $foo;
>
> This would be consistent with parameters. And I think it goes along well with
> return types at the end:
>
> public Foo $foo;
> public function foobar(): FooBar;
>
> Here, it’s clear the second item is a function, and the previous item is a
> property of type Foo.
>
> …but hey, I could be wrong. Does this make sense to anyone?
To me it makes sense. However
Foo function foo(Bar bar) {}
also makes sense, as the type of bar would be "Foo function(Bar)".
--
Christoph M. Becker
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php