Re: [RFC] Scalar Type Hints v0.2
| From: | Thomas Bley | Date: | Thu, 15 Jan 2015 22:25:40 +0000 |
| Subject: | Re: [RFC] Scalar Type Hints v0.2 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-80599@lists.php.net to get a copy of this message | ||
I think the problem with the current rfc is:
test(42);
function test(string $a) does test((string)$a);
function test(array $a) does not test((array)$a); although casting would be possible.
So for consistency we might change the syntax or adapt array/object type hints with casting
(BC-break).
Regards
Thomas
Rowan Collins wrote on 15.01.2015 23:09:
> On 15 January 2015 20:16:54 GMT, Thomas Bley <mails@thomasbley.de> wrote:
>>What about doing both weak and strict with two different syntaxes?
>>
>>public function __construct(string $name, $age as int, $cuteness as
>>float, bool $evil) {
>>
>>string $name // strict
>>$age as int // weak
>>$cuteness as float // weak
>>bool $evil // strict
>>
>>"as" Syntax is taken from SQL92.
>>
>>Regards
>>Thomas
>
> This is what some are proposing, but with slightly different syntax choices,
> inspired by existing cast operators:
>
> public function __construct(string $name, (int) $age, (float) $cuteness, bool
> $evil)
>
> Like literally every proposal in this area, some people think it's The
> Solution, others absolutely hate it.
>
> Andrea has stated (if I'm not paraphrasing too badly) that a major reason for
> putting the caller in control, not the definer, is that it's easier to reason
> about code where all the calls you are looking at follow one behaviour,
> regardless of where they were defined.
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>