News for hackers. Stuff that matters.
Re:PHP 8 by daneel_w on Thursday November 26, 2020 @11:14AM (#25221206)
In the absence of strict type checking it would be terrible, but == performs a loose comparison, and "foobar" cannot cast to any other number than 0. Perl will go about it the exact same way. Contrast this against strict comparison, "0" === 0, which will evaluate as false.
Re:PHP 8 by xeeeeeeeeeeenu on Thursday November 26, 2020 @11:47AM (#25221503)
>Perl will go about it the exact same way.

No, Perl is completely different and IMO it's the only mainstream dynamically typed language that has sane comparison operators.

Perl has two sets of operators, numeric (==, +, *, <, >, <=> etc.) and stringwise (eq, ., lt, gt, cmp etc.). You can think of them as explicit (but concise) casts. For example, Perl's $foo eq $bar is roughly equivalent to Python's str(foo) == str(bar).

It is true that "foobar" == 0 returns true in Perl but, as I showed above, it does that for a completely different reason.

Re:PHP 8 by hypertele-Xii on Thursday November 26, 2020 @11:18AM (#25221239)
Maybe "foobar" should evaluate to NaN.
Re:PHP 8 by _-___________-_ on Thursday November 26, 2020 @11:31AM (#25221347)
Does PHP have separate int and float types? NaN is a float value and I would expect 0 to be an int.
Re:PHP 8 by ragnese on Thursday November 26, 2020 @11:52AM (#25221564)
It does