Types on the right or on the left
| From: | Robert Stoll | Date: | Mon, 03 Nov 2014 15:07:41 +0000 |
| Subject: | Types on the right or on the left | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-78577@lists.php.net to get a copy of this message | ||
Heya,
Its seems to me that more and more RFC are proposed to augment PHP's syntax with some form of
additional type hints.
The following RFC proposes to add a type hint for the return type of a function/method:
https://wiki.php.net/rfc/returntypehinting
It adds the type hint on the right hand side of the function (of the identifier). In contrast to
parameters where the
type hint is placed on the left hand side of the identifier.
Mixing both, having some types on the left and others on the right, seems like another inconsistency
in the language
design to me.
I think now is the time where we should decide what convention we want to stick to in the future
(either left or right).
PHP 7 is the perfect time to make a change. I do not want to take sides because I am not yet sure
what I prefer but
following some examples for both conventions:
function foo($a : Foo, $b : array) : void {} // types on the right
function void foo(Foo $a, array $b){} // types on the left
Assuming PHP will introduce type hints for properties at some point
class A{
private $f : Foo; //types on the right
private Foo $f; //types on the left
}
Assuming PHP will introduce type hints for variables at some point
$a : int = 1; //types on the right
int $a = 1; // types on the left
Assuming PHP will introduce generics and typed arrays at some point.
function foo<T>($a : T, $b : array<Bar>, $c : Foo[]) : callable<T, Car> {} //
types on the right
function callable<T, Car> foo<T>(T $a, array<Bar> $b, Foo[] $c){} //
types on the left
Thoughts?
Cheers,
Robert