> On 4 Nov 2014, at 11:50, Chris Wright <[email protected]> wrote:
>
> On 4 November 2014 10:32, Andrea Faulds <[email protected]> wrote:
>
> > I thought it was inconsistent, but after discussions on StackOverflow, I
> > don't think it actually is. > Return types describe the return type of a
> > function, not the type of a function. So there's no reason > they have to
> > go before the function name like parameter types do.
>
> So, in a sentence:
>
> In PHP, input types go on the left and output types go on the right.
>
> This sounds like a convention that could be established and followed, and
> no-one could reasonably call it inconsistent if it was adhered to.
>
That’s not quite what I meant, but I’d also agree with that convention.
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?
--
Andrea Faulds
http://ajf.me/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php