Re: [Discussion] is_string(), string type and objects implementing __toString()

From: Date: Sat, 11 Mar 2017 14:06:19 +0000
Subject: Re: [Discussion] is_string(), string type and objects implementing __toString()
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  Groups: php.internals 
Request: Send a blank email to internals+get-98484@lists.php.net to get a copy of this message
On 11 March 2017 13:53:10 GMT+00:00, Andrey Andreev <narf@devilix.net> wrote: >I don't disagree with that in general, but strictly rejecting strings >and other non-integer values would alleviate the problem for a >majority of cases; i.e. would solve the 90% problem. I guess I just don't see that as 90% at all. The interesting values to detect are the ones that are out of range, not just that somebody wrote '4' instead of 4. >What I strongly disagree on is that I should be happy with coercion, >and the almost religious resistance against (non-overridable) strict >scalar typing. For me, it's about division of responsibility: a library defines a contract, and it's up to me how I meet that contract. If I go through writing (string) everywhere, or use a pre-compiler that does that for me, I'm meeting the contract. It's no more the library's business than whether I use an IDE with dozens of templates, or hand craft my code in notepad. All coercive typing does is turn that pre-compiler on by default. What's more interesting to me is how the library can express the contract it actually wants, and scalar types by their nature make for weak constraints. All of the examples you've given are good illustrations of that, and that's why I've been trying to tease out some things that the language could do to actually help with those cases. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#98484) next »