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

From: Date: Sat, 11 Mar 2017 13:34:03 +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  Groups: php.internals 
Request: Send a blank email to internals+get-98480@lists.php.net to get a copy of this message
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. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#98480) next »