Re: Types on the right or on the left

From: Date: Tue, 04 Nov 2014 18:23:28 +0000
Subject: Re: Types on the right or on the left
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-78662@lists.php.net to get a copy of this message
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

« previous php.internals (#78662) next »