Re: [RFC] Scalar Type Hints v0.2

From: Date: Thu, 15 Jan 2015 16:11:00 +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-80564@lists.php.net to get a copy of this message
Hi, On Thu, Jan 15, 2015 at 5:31 PM, Pavel Kouřil <pajousek@gmail.com> wrote: > 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))". You're basically asking what's the difference between weak and strong typing ... it's rather philosophical. It's the intent that's important, not the end result, which is why I see the caller-controlled switch as pointless. Cheers, Andrey.

« previous php.internals (#80564) next »