Top 10 PHP Classic Traps
summary
Covers concrete pitfalls and fixes: use strpos() === false not == to avoid confusing 0 with false; prefer const over define() for compile-time constants (case‑insensitive define() is deprecated since 7.3 and removed in 8.0); replace repeated concatenation/print with echo or collect and join to avoid reallocations; buffer CSV into php://memory with fputcsv then write once; beware operator precedence (and vs &&), foreach by reference leak unless unset, unset properties become missing, DateTime intervals not strtotime month arithmetic, and use hrtime() on PHP 7.3+ for monotonic timing.
AI-written summary · about
chapters (22)
- 0:00Introduction and setup
- 2:28Strpos false vs zero trap
- 5:42Constant defining performance
- 10:02Echo vs print concatenation
- 15:02CSV writing performance
- 18:34Operator precedence confusion
- 23:21Logical operators and types
- 25:29Variable variable injection
- 27:17Real vs float deprecation
- 28:24String character access
- 29:50Substring vs strtolower order
- 32:45Array merging inefficiency
- 37:09Double square bracket quirks
- 40:25Regex optional capture trap
- 42:08Column names vs indices
- 44:17Unsetting class properties
- 47:06Date calculation pitfalls
- 51:09Script timing accuracy
- 52:33Reference loop trap
- 55:28List short syntax updates
- 56:56Array destructuring
- 57:59Top 10 recap and conclusion
related talks
49mTop 10 PHP coding traps
45mModernizing PHP one edge case at a time
39mClean Coding - 10+ Techniques To Clean Your PHP Code
12m10 Awesome things that most people won't notice in PHP
01h 04mPrepare Your Code for PHP 9: PHP 8 Deprecations Explained
01h 12m25 Years of PHP
35mPHP is evil (Defensive programming)
44mModern PHP Standards and Community
