Re: [RFC] Scalar Type Hints v0.2
| From: | Pavel Kouřil | Date: | Thu, 15 Jan 2015 15:31:54 +0000 |
| Subject: | Re: [RFC] Scalar Type Hints v0.2 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-80557@lists.php.net to get a copy of this message | ||
On Thu, Jan 15, 2015 at 4:19 PM, Jordi Boggiano <j.boggiano@seld.be> wrote:
>
> Right now, or with only weak hints, if a library decides to implement strict
> typing, they'll skip the scalar hints and check types with something like
> the assert lib [1]. A user calling it with random data would *always* get
> exceptions. There is no way for the library to use scalar hints to play nice
> with weak-typed callers as it would not be able to type check anymore in
> that case.
>
Why would the libraries writers use the checks inside the method
instead of the typing, even in the case of the weak typing? I don't
see a single reason to do so, because if they ask for an "int" in the
method signature, they will get an int or the method won't get called
at all. See the example in the RFC with the "if (!is_int($i))".
Pavel Kouril