maybe you can add a few examples to the type table in the rfc, so everybody knows how it actually works:
function test(int | float | string $a) {var_dump($a);} test(42.0); // float(42) test('42'); // string(2) "42" function test2(int $a) {var_dump($a);} test2(42.0); // int(42) test2('42'); // int(42) function test3(int|bool $a) {var_dump($a);} test3('foo'); // true Regards Thomas Bob Weinand wrote on 03.06.2016 14:30: > >> 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 > > > > > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php