> Am 3.6.2016 um 14:18 schrieb Rowan Collins <rowan.coll...@gmail.com>: > > On 03/06/2016 12:59, Bob Weinand wrote: >>> function l(string | float $x) { echo gettype($x); } >>> l("1.5a"); // I would expect string, but float would succeed if attempted >> >> Exact matches *ALWAYS* match without coercion. > > Gah, I keep making that mistake in my examples. I did say I was struggling to > get my head around things! ;) > > I'm still missing an explanation of exactly where you derived the current > proposed rules from, though. The RFC just states "these rules are not an > invention of this proposal", but goes on to say "applies PHP casting rules in > a sane way", which implies some decisions were involved in drawing up these > rules. > > I think you may be right that the rules are as simple as they can be, and I > don't want to waste too much of your time, but a basic summary of the > reasoning used would be much appreciated. > > Regards, > -- > Rowan Collins > [IMSoP]
The *weak casting* rules (i.e. what gets converted how and what can be converted to the other type) are not an invention of the proposal. The proposal however defines the specific order. I’ve added a reasoning why not left-to-right now. As this seemed to be asked multiple times. Also, the specific reasoning why I propose that specific order the rules are in: > Otherwise PHP's casting rules are applied in an order to be as lossless as > possible. That’s really the only motivation behind that. Bob