Re: [RFC] Scalar Type Hints v0.2
| From: | Jordi Boggiano | Date: | Thu, 15 Jan 2015 15:35:47 +0000 |
| Subject: | Re: [RFC] Scalar Type Hints v0.2 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-80558@lists.php.net to get a copy of this message | ||
On 15/01/2015 15:31, Pavel Kouřil wrote:
On Thu, Jan 15, 2015 at 4:19 PM, Jordi Boggiano <j.boggiano@seld.be> wrote:I mean that if someone wants strict typing they won't want to use weak hints because that would coerce the data before they can verify it and ensure their code is strictly typed. Therefore the best course of action is to have no hint + check manually, like they are doing now with such libs. Cheers -- Jordi Boggiano @seldaek - http://nelm.io/jordiRight 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))".