On 3 June 2020 09:50:23 BST, Deleu <deleu...@gmail.com> wrote: > `is_numeric` has been with PHP for >so long that I don't think we would ever be able to have a `numeric` >type-hint that doesn't align with it, which imho means we either have it or >we don't, a 3rd option where a possible type-hint that is inconsistent with >the function seems worse than not having it.
I agree, but my conclusion is that the best answer is "don't have it" - I don't think the use cases are common enough to deserve a language feature rather than just using the existing function. >My point is that I don't look at the language validation to protect my code >against unexpected values and I can setup validation to deal with that. If it's not to protect against unexpected values, then what is it for? >What complicates things is that I want to avoid having a force-cast >which is not safe for my usage because I want to preserve `null` Yes, the combination of strict cast and nullable cast would sometimes be useful, although the syntax might get messy - (int?!)$foo looks horrible. Since we already have ?int though, this doesn't seem a strong reason to add ?numeric meaning almost the same thing. > while not having to disable strict_types It feels a bit like you want to "have your cake and eat it" here - if you want a loose check and aren't worried about a few unusual values getting through, why are you running in strict_types mode in the first place? Regards, -- Rowan Tommins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php