I would like to pick up this discussion again - now that the return type hint 
RFC has passed, congratulations :)

As a quick reminder, this discussion should not be whether we want to put the 
return types on the left or on the right but mainly if we want to have 
consistency (I do not want to downgrade the return type hint RFC either, that 
is the reason why I have waited till the vote was closed). Once agreed upon 
that consistency should be key when it comes down to the place of type hints, 
we can then discuss what approach PHP shall take in the future (all left or all 
right).  

The more I think about it the more I am in favour of putting types on the right 
hand side. I think it is more readable and less ambiguous. Consider the 
following:

class A{
   private Foo $a; //is "Foo" a modifier as well?
   private static $b; //or is "static" a type?
}

vs.

class A{
  private $a : Foo;
  private static $b;
}

Assuming we will introduce parameter modifiers such as final or similar in the 
future, then it is also less ambiguous for parameter type hints:

function foo(final A $a, final $b){}

vs

function foo(final $a : A, final $b){}

I am sure people will tell me that such a change (all types on the right, 
parameter type hints as well) is huge BC and unfeasible. I would agree that it 
is a huge BC but I would claim it is necessary and manageable. Code could be 
migrated automatically with an appropriate tool and it does not need to happen 
for PHP 7 but maybe for PHP 8. Besides, pretty much the same impact has the 
return type RFC now, because the manual should be updated accordingly to 
reflect the new syntax IMO. Sounds like lot of work but it should be possible 
to migrate the docs with a tool. And it needs to be done IMO otherwise the 
WTF/minute measurement will increase when using PHP (due to lot of "WTF! In the 
docs the return types are on the left and in code they are on the right hand 
side") - but maybe I am wrong.

Anyway, I am primarily in favour of consistency - regardless if all left or all 
right - and mixing both styles is a very bad idea IMO - do you know any 
language which has taken a mixed approach (besides Hack)?  

Cheers,
Robert


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to