I say that php breaks math entirely, and is therefore bad. “” == null returns true null == [] returns true “” == [] returns false.

In more recent versions it gets worse, because it has 0 == “any text” return true, “any text” == true return true, and 1 == true return true So indirectly 1 = 0, and now math is more directly broken.

If you’re trying to directly compare different variable types in any language without strong typing, you’re going to have edge-case results which you might not expect.

My “coding like a moron” message still stands. PHP isn’t a strongly typed language and it doesn’t tell you off for trying stupid stuff like comparing a string with an int. Nor do other languages like JavaScript.

Also using duck typing fails against php is pretty funny when it’s being compared against JAVASCRIPT of all things.

Rikudou_Sage
link
fedilink
11Y

Just… don’t use ==? I haven’t used it in a few years.

I just tested these out out of curiosity.
0==“text” returns false in PHP 8.2 as I’d expect.

The others make sense in the way that php juggles between types. An empty variable can type-juggle to null, but an array can’t be directly compared with a string.

(Although you wouldn’t really want to compare an array with a string, PHP just treats an array as greater than other variables. So weirdly, ([] > “”) == true.)

Create a post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
  • 1 user online
  • 120 users / day
  • 257 users / week
  • 744 users / month
  • 3.72K users / 6 months
  • 1 subscriber
  • 1.48K Posts
  • 32.5K Comments
  • Modlog