Hello,

On Wed, Jan 14, 2015 at 12:22 PM, Andrea Faulds <a...@ajf.me> wrote:
>
> Hi Julien,
>
>> On 14 Jan 2015, at 10:14, Julien Pauli <jpa...@php.net> wrote:
>>
>> Using declare() IMO, is a PITA.
>> Everything that can be done without the use of declare(), must be done 
>> without declare().
>>
>> I would have prefered different syntax, like the ones we disccussed many 
>> years ago , having strict checks with the foo(string $a) syntax, and 
>> non-strict check with the foo((string) $a) syntax.
>
> Actually, this approach came about mostly to avoid that. I don’t really like 
> the idea of mixing and matching weak and strict type checks. Having some 
> functions using (int) and (string), others use int and string, and others 
> still use both, would be confusing. Plus, it would mean that you’d be forced 
> to follow the personal preference of the API authors.
>
> With this RFC, yes, you have to put an extra line at the top of the file. But 
> it has the advantage that everything follows the same behaviour, even 
> extension/built-in functions. That’s what I like about it.

I don't understand why it should be a bad thing that the API author
forces rules on the consumer. The opposite is IMO fundamental to the
concept of an API - the rules specified by the author are a contract
that the consumer agrees to, and which allows for the whole thing to
work properly.

In this form, I don't get any benefit from strict type checks, because
I only want them so that writing foo(int $bar) guarantees me that the
caller *passed* an integer. Instead, I'd have to NOT use a type hint,
and instead do an is_int($bar) check inside ... this beats the whole
purpose.

This caller-controlled switch very much reminds me of
mbstring.func_overload, which I didn't care much for, until one day I
saw how it breaks all crypto code that authors had otherwise written
very carefully.

I prefer Julien's (int) $weak vs. int $strong syntax better (which is
what I've always wanted), but I don't care much if it's a declare()
statement, just as long as the author controls the behavior.
And while I'm on that - thank you for this proposal (specifically the
0.2 version), Andrea. Finally an RFC that allows both weak and strict
scalar type checks instead of the "can't go in both directions"
nonsense that has blocked this feature for years.

Cheers,
Andrey.

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

Reply via email to