Hi Zeev, On Wed, Feb 18, 2015 at 2:31 PM, Zeev Suraski <z...@zend.com> wrote: >> Consider the following signature: >> >> function foo(int $bar) {} >> >> In the case of a *string* representation of a hexadecimal number, the >> following would error only on the last iteration with a weak hint, and on >> the >> very first if it was a strict hint: >> >> for ($i = 0; $i < 11; $i++) >> { >> foo(base_convert($i, 10, 16)); >> } >> >> And when I said leading zeros, I was talking about fixed-length string >> identifiers such as '001', '002', etc. where you may *unintentionally* >> pass >> such a value to a function that deals with ... quantities, for example. A >> strict >> hint in that case would immediately catch this logical error while a weak >> hint >> would silently ignore the leading zeros and will happily treat the value >> as an >> integer. Again, the precondition here is that it's not an integer value >> that >> happens to be stored as a string, but a non-integer value that just looks >> like >> an integer. > > Thanks the example Andrey, it's helpful. > > My goal with asking for these use cases isn't to claim that they never > exist, and I certainly don't want to get into a theological discussion. My > goal is to try and figure out whether many, if not all, proponents of strict > typing would be willing to live with a compromise on single set of rules, > that on one hand would be a lot stricter than what was proposed for weak > typing in the v0.3 RFC (bool->anything fails, any string that's not strictly > looking like a number incl. "100 dogs" -> int/float fails, float->int > fails), but on the other hand, would allow certain lossless conversions > (numeric string -> int/float, int->float, toString() to string, etc.) to > work. >
I didn't imply that you meant any of that, not in this thread anyway ... If I've done it previously, it's only because your choice of words had made it appear that way. You don't need to defend yourself everytime I quote you. :) > When people from both schools of thought (strict/weak) come to evaluate this > possibility, remember that we don't need a solution that works in 100.0% of > the cases. Edge cases, again, be them strict or weak, can always be > implemented with a bit of custom code inside the function - the important > thing is to get a system that addresses the vast majority of cases. > Well, that's usually the case because you simply can't provide a 100% solution. In this case, I believe we can satisfy if not 100%, then 99% of the use cases by simply providing both weak and strict hints simultaneously. From my POV, further restricting conversion rules for weak hints is deffinately an improvement, but still a limited one. There's no *technical* limitation to including two solutions to the problem, so I'd rather do that and be practical instead of following a belief for what does or doesn't belong in PHP. I know you're on the flip side, so we shall agree to disagree on that. Cheers, Andrey. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php