Returntypehinting RFC

RFC'd by @morrisonlevi

PR'd for review + CI

https://wiki.php.net/rfc/returntypehinting
I suppose the syntax with column came from Virt family languages (Pascal,
Modula, Ada, etc).
It looks natural for me and it shouldn't make any grammar conflicts with
ternary operator.

Thanks. Dmitry.




On Thu, Aug 21, 2014 at 4:10 AM, sun <notifications@github.com> wrote:

> In Zend/tests/return_hint/008.phpt:
>
> > @@ -0,0 +1,24 @@
> > +--TEST--
> > +Basic return hints covariance interfaces
> > +--FILE--
> > +<?php
> > +interface foo {}
> > +interface bar extends foo {
> > +	public function foo() : foo;
> > +}
> > +
> > +
> > +class qux implements bar {
> > +	public function foo() : bar {
>
> Sorry for commenting here instead of the list, but in looking through the
> example code snippets in all these tests, a single question occurred to me
> all over again:
>
> Why is there a colon between the function signature and the return type
> hint?
>
> The colon is one of the few operators in PHP that is consistent with other
> languages; specifically in ternary operators. The suggested new usage makes
> code visually appear as function this OR that.
>
> Is there a particular reason for why we need it? What's wrong with the
> following?
>
> -  public function foo() : bar {+  public function foo() bar {
>
> The RFC only states the following in its References
> <https://wiki.php.net/rfc/returntypehinting#references>:
>
> Suggestion 5 is nearly compatible with this RFC; however, it requires the
> addition of a new token T_RETURNS. This RFC opted for a syntax that does
> not require additional tokens so returns was replaced by a colon.
>
> At the same time, the Position
> <https://wiki.php.net/rfc/returntypehinting#position_of_type_declaration>
> chapter does not show a colon in its comparison to other languages:
>
>
>    - After the parameter list: function_name() return_type;
>
>  To be clear: Only questioning why there has to be a delimiter. I'm *NOT*
> questioning the placement/position of the return type hint. (After thinking
> through all possible options, the placement makes sense to me.)
>
> *Apologies in case this was discussed before already. I'm new to
> internals. I read the RFC. The mailing list based infrastructure makes it a
> bit hard to retroactively follow discussions. In case this was actively
> decided already, feel free to just point me to the thread that I may have
> missed.*
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/php/php-src/pull/653/files#r16514231>.
>