> -----Ursprüngliche Nachricht-----
> Von: Ryan Pallas [mailto:[email protected]]
> Gesendet: Sonntag, 5. Juni 2016 14:22
> An: Robert Stoll
> Cc: Bob Weinand; Andrea Faulds; [email protected]
> Betreff: Re: [PHP-DEV] Re: [RFC] [PRE-VOTE] Union types
>
>
>
> On Sun, Jun 5, 2016 at 6:09 AM, Robert Stoll <[email protected]> wrote:
>
>
> Hi Andrea, Bob
>
> > -----Ursprüngliche Nachricht-----
> > Von: Bob Weinand [mailto:[email protected]]
> > Gesendet: Sonntag, 5. Juni 2016 01:00
> > An: Andrea Faulds
> > Cc: [email protected]
> > Betreff: Re: [PHP-DEV] Re: [RFC] [PRE-VOTE] Union types
>
> >
> >
> > > Am 05.06.2016 um 00:55 schrieb Andrea Faulds <[email protected]>:
> > >
> > > 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?
>
>
>
> In this case, A will always be taken, because of the loose comparison (==).
> Basically:
>
> var_dump("" == ""); // bool(true)
> var_dump(0 == ""); // bool(true)
> var_dump(false == ""); // bool(true)
>
My fault, so what about
if ($a === "") {
}
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php