J
Jeffery Paris
If you’re new to PHP, here’s the “proper way” to do comparisons—and why it matters.
1) Default to strict comparisons (=== and !==)
Strict comparisons check both value AND type. That prevents PHP from “helpfully” converting values behind your back. Loose comparisons (==) can make things like 0, "0", false, null, and "" behave as if they’re the same, which is a fast path to confusing bugs (and occasionally security issues).
2) Normalize types at the edges
Most weird comparison bugs come from...
Here’s the “proper way” to do comparisons—and why it matters.
Continue reading...
1) Default to strict comparisons (=== and !==)
Strict comparisons check both value AND type. That prevents PHP from “helpfully” converting values behind your back. Loose comparisons (==) can make things like 0, "0", false, null, and "" behave as if they’re the same, which is a fast path to confusing bugs (and occasionally security issues).
2) Normalize types at the edges
Most weird comparison bugs come from...
Here’s the “proper way” to do comparisons—and why it matters.
Continue reading...