Re: [RFC] Scalar Type Hints v0.2

From: Date: Thu, 15 Jan 2015 17:13:22 +0000
Subject: Re: [RFC] Scalar Type Hints v0.2
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-80576@lists.php.net to get a copy of this message
Hi Mike, > On 15 Jan 2015, at 17:07, Mike Willbanks <pencap@gmail.com> wrote: > > I may not have described this clearly. If I make a library with a method that states an int, > the declarative syntax now makes me have to take both due to your earlier comment on that userland > would define the condition. This means that if I declared handling inside my library to be strict > but the caller was in weak, I would need to handle that condition. How, exactly, would you need to handle that condition? You don’t need to do anything yourself. As the RFC itself says: > In both approaches, the function will always get exactly the argument type it asks for. In the > case of strict type-checking, this is done by rejecting incorrectly-typed values. In the case of > weak type-checking, this is done by rejecting some values, and converting others. Therefore, the > following code will always work, regardless of mode: > function foobar(int $i) { > if (!is_int($i)) { > throw new Exception("Not an integer."); // this will never happen > } > } No matter whether foobar() is called from strictly type-checked or weakly type-checked code, the $i argument you get will always, without fail, be an integer. Thus, I do not see how you "would need to handle that condition”. > Now from that perspective I cannot rely that I am in strict and would have to handle the > default weak even although I declared in my class that i wanted strict mode which only affected the > code inside of that file. That's ultimately what I am saying and why I am stating it would > have to handle both conditions. In reality, you'd always act as if you were in a weak mode > supporting that case. I… really don’t understand, I’m sorry. Are you complaining that if a caller uses the weak mode, they are not bound by strict types? Why do you want to affect the code of the caller? -- Andrea Faulds http://ajf.me/

« previous php.internals (#80576) next »