How to Sort by Multiple Fields With usort
One comparison function. Sort by name then age. No loops.
Quick PHP chats, tips, and insights in a fast, simple format
How to Sort by Multiple Fields With usort
One comparison function. Sort by name then age. No loops.
How to Capture Variables in Closures
use ($var) brings outer scope in. Read. Modify with use (&$var).
Why does this PHP retry charge customers twice?
Why does this PHP retry logic charge customers twice in production. The PHP code retries a payment call after a timeout without an idempotency key, so the gateway processes duplicates. In PHP billing services this creates double charges and refunds.
#whatswrongwiththisphpcode #phpbug #phpproductionbug #phpdebugging #phpbackend #phpcodereview #phpsecurity #phpperformance #phpreliability #phpapi #phpw...
How to Use Ternary and Null Coalesce
? : for if-else. ?? for null fallback. ??= for assign if null.
File Get Contents Loads 2GB Crashing 47 Web Servers?!
MEMORY EXPLOSION! file_get_contents() loads ENTIRE 2GB file into RAM! 47 web servers CRASHED! Tax deadline missed! 12K users disconnected! $12M class action lawsuit! Lead developer FIRED!
#php #phpdisaster #filegetcontents #memoryexhaustion #servercrash #taxdeadline #productionbug #phpshorts #phpwtf #outofmemory #careerending #cascadefailure
Why is this PHP temp file creation risky?
Why is this PHP temp file creation risky in a report worker. The PHP code writes to a predictable path in /tmp, which can be hijacked with symlinks. In PHP servers this can overwrite sensitive files.
#whatswrongwiththisphpcode #phpbug #phpproductionbug #phpdebugging #phpbackend #phpcodereview #phpsecurity #phpperformance #phpreliability #phpapi #phpwebdevelopment #phpengineering #phptempfile #phpsymlinkat...
Search Query Throttle
Protect search clusters with per-user and global limits.
#php #python #search #throttling #ratelimiting #performance #backendsafety #reliability #viralcoding #growth
How to Prevent File Upload Path Traversal
Two dots can escape any upload folder.
How to Shuffle Arrays Randomly
shuffle mutates. array_rand picks keys. Know the difference.
Array Merge RESETS Numeric Keys Destroying 2.3M Order IDs?!
ARRAY_MERGE DISASTER! Numeric keys RESET to 0,1,2,3! Order 1001 becomes 0! Payment records can't match! 2.3M orders lose IDs! $8.7M shipping chaos! Database architect FIRED!
#php #phpdisaster #arraymerge #numerickeys #datacorruption #orderids #productionbug #phpshorts #phpwtf #arraychaos #careerending #keyreset
Float Precision Issue
Does 0.1 + 0.2 equal 0.3 in PHP? The answer will surprise you! Float precision trap that catches everyone!
Why does this PHP error_reporting hide the real exception?
Why does this PHP error_reporting hide the real exception in a catch. The PHP code sets error_reporting to 0 inside try. In PHP error handling this suppresses the actual error and hides root cause.
#whatswrongwiththisphpcode #phpbug #phpproductionbug #phpdebugging #phpbackend #phpcodereview #phpsecurity #phpperformance #phpreliability #phpapi #phpwebdevelopment #phpengineering #phperrorre...
Why does this PHP SplFileObject seek break iteration?
Why does this PHP SplFileObject seek break iteration in a parser. The PHP code seeks during foreach over the same object. In PHP file parsing this causes skipped or repeated lines.
#whatswrongwiththisphpcode #phpbug #phpproductionbug #phpdebugging #phpbackend #phpcodereview #phpsecurity #phpperformance #phpreliability #phpapi #phpwebdevelopment #phpengineering #phpsplfileobject #phpseek #phpit...
How to Sanitize Input With filter_input
Filter input early to block obvious junk.
What's wrong with this PHP array_search check?
What's wrong with this PHP array_search check in an allowlist. The PHP code treats index 0 as false, so the first allowed user is rejected. In PHP access control this silently blocks valid requests.
#whatswrongwiththisphpcode #phpbug #phpproductionbug #phpdebugging #phpbackend #phpcodereview #phpsecurity #phpperformance #phpreliability #phpapi #phpwebdevelopment #phpengineering #phparraysearch #phpin...
How to Get First or Last Key Without reset
array_key_first and array_key_last. No side effects. PHP 7.3+
This PHP Move Crushes Factory New Everywhere
💡 Level Up Your PHP! This PHP Move Crushes Factory New Everywhere shows the difference between old and modern PHP. Learn PHP 8 features that will change your code! Your code quality will improve! #PHP #WebDev #CodingTips #coding
#php #programming #coding #webdevelopment #softwareengineering #juniorvssenior #codereview #programmingtips #phptutorial #codingtutorial #bestpractices #phpprogramming #softwar...