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

From: Date: Sat, 11 Mar 2017 13:53:10 +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-98481@lists.php.net to get a copy of this message
On Sat, Mar 11, 2017 at 3:34 PM, Rowan Collins <rowan.collins@gmail.com> wrote: > On 11 March 2017 13:23:16 GMT+00:00, Andrey Andreev <narf@devilix.net> wrote: >>Ironically enough, the following code executes silently: >> >> $array = ['a', 'b', 'c']; >> sort($array, '2234234324'); >> >>If you don't see the problem with that, I guess it does make "no sense >>at all" from your POV. Just agree to disagree. > > > I see a problem with that, but I see exactly the same problem with this: > > $array = ['a', 'b', 'c']; > sort($array, 2234234324); > > The fact is, "int" is far too loose a type constraint to meaningfully validate that > parameter. The solution to that is not to be more strict in rejecting strings, but to create richer > types of constraint: enums, unions, domains, etc. > 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. What I strongly disagree on is that I should be happy with coercion, and the almost religious resistance against (non-overridable) strict scalar typing. Cheers, Andrey.

« previous php.internals (#98481) next »