Hi Andrea, Bob > -----Ursprüngliche Nachricht----- > Von: Bob Weinand [mailto:bobw...@hotmail.com] > Gesendet: Sonntag, 5. Juni 2016 01:00 > An: Andrea Faulds > Cc: internals@lists.php.net > Betreff: Re: [PHP-DEV] Re: [RFC] [PRE-VOTE] Union types > > > > Am 05.06.2016 um 00:55 schrieb Andrea Faulds <a...@ajf.me>: > > > > Hi again, > > > > In an attempt to be constructive, I have implemented an alternative > > approach to weak scalar type selection here: > > > > https://github.com/krakjoe/php-src/compare/multi-types...TazeTSchnitzel:multi-types-roulette > > > > Where there is no exact scalar type match, this patch uses an algorithm > > originally suggested by Nikita, wherein we use > rand() to pick which type to cast to. > > > > This is much simpler than having a type precedence matrix, and thus is > > easier to remember and reason about. The choice > of selection function means that no particular use-case is privileged. Given > PHP's scalar types are roughly equivalent (after > all, PHP juggles them freely), this apparently unorthodox selection process > should nonetheless produce sensible results in > most cases. > > > > Please tell me your thoughts! > > > > -- > > Andrea Faulds > > https://ajf.me/ <https://ajf.me/> > This is the holy grail I was hunting for so long! > > All my computational problems can be solved by a simple rand()! > > In case nobody objects I'm going to merge that straight ahead into php-src > 7.0 (no need for master-only, after all it's no real > BC break!). > > Thanks a very much!!! > > Bob
Not sure if this is a clever idea. I haven't read all emails so bear with me if this is more than clear. What happens with the following? function foo(int | string $a) { if ($a == "") { //a } else { //b } } foo(false); What branch is taken? Is it taken randomly? -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php