Top 10 PHP coding traps
summary
Static analysis across many PHP projects finds concrete patterns and fixes: 26 ambiguous string functions that return 0/false confusion (php8 adds str_contains), 13 OpenSSL-like functions that return -1/0/1 so boolean checks hide errors, and a measured 2% use of case-insensitive constants. Recommendations include replacing define() with const, using echo with multiple args, buffer fputcsv into php://memory then rewind to avoid repeated disk flushes, and prefer foreach/hoisted count or variadic array_merge to avoid repeated reallocations.
AI-written summary · about
chapters (21)
- 0:00Intro
- 1:06Top 10 PHP classic traps
- 3:48strpos(), the legendary
- 5:06The real face of strpos()
- 8:00The lesser legend of strpos()
- 12:24define() is on the way out
- 13:49Constant static expressions
- 18:00echo doesn't "function"
- 18:27A reverse problem
- 20:43Dump it like Beckam
- 22:40Logic, written in full
- 25:16Order matters
- 29:25A matter of string
- 31:20Sneak master level 100
- 33:02Far from reality
- 33:33I want the magic property
- 35:25Looping with array_merge()
- 40:09Looping with concat
- 42:21Looping with addition
- 43:25Missing subpattern
- 46:41Want to check your code?
related talks
59mTop 10 PHP Classic Traps
39mClean Coding - 10+ Techniques To Clean Your PHP Code
45mModernizing PHP one edge case at a time
01h 04mPrepare Your Code for PHP 9: PHP 8 Deprecations Explained
12m10 Awesome things that most people won't notice in PHP
35mPHP is evil (Defensive programming)
45mPHP: Particularly Horrible Programs
01h 12m25 Years of PHP
