Re: [RFC] Scalar Type Hints v0.2
| From: | Andrey Andreev | Date: | Wed, 14 Jan 2015 11:37:18 +0000 |
| Subject: | Re: [RFC] Scalar Type Hints v0.2 | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-80458@lists.php.net to get a copy of this message | ||
Hi again,
On Wed, Jan 14, 2015 at 1:21 PM, Andrea Faulds <ajf@ajf.me> wrote:
> Hi Andrey,
>
>> On 14 Jan 2015, at 11:10, Andrey Andreev <narf@devilix.net> wrote:
>>
>> 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.
>
> Why? What is wrong with a caller choosing to use weak type hints? Either way you receive an
> integer.
Because it's pointless. Why would I want strict checks if I only cared
for getting an integer? The whole point is that I care for what the
caller passed, that I want specifically a check instead of a cast.
Cheers,
Andrey.