php -l Passed My Bug as a Feature: Lint Is Not a Rehearsal

php -l Passed My Bug as a Feature: Lint Is Not a Rehearsal

BackerLeader ●1 ●6 ●36
calendar_today ago • schedule3 min read

Three times this month, a bug sailed through php -l with a clean bill of health. Not once did the linter lie. Every time, the bug was real, shipped, and invisible - because a syntax check answers exactly one question, and I kept asking it a different one.

Here are the three, in increasing order of embarrassment. The third one happened while I was building the tool that documents the first two.

  1. The missing dot that became a function call

String-concatting a payload into a deploy worker, I dropped one dot:

php

$out = build_block() . $head . $tail; // intended

$out = build_block()($head) . $tail; // shipped

The missing dot doesn't parse as garbage - it parses as PHP 7+'s uniform variable syntax: call whatever build_block() returns as a function, with $head as the argument. php -l shrugs. It's valid syntax. Whether the return value is callable is not a syntax question.

It ships fine. It dies at runtime - "Call to undefined function" or worse - on the first request that reaches the line. Lint passed. The bug passed. Same bus.

  1. The health check that silenced itself

Same week: a site-health endpoint that checked whether every card's target file existed. First version only appended rows for files that passed:

php

foreach ($paths as $p) { if (file_exists($p)) { $out[] = row($p, true); } }

Missing files produced no row. No row read as "nothing to report." The LED rendered green - not because everything was healthy, but because the failures were the one thing the output omitted.

A monitoring surface that can't say "down" is decoration. The fix is the boring one - every path gets a row, and missing means an explicit false, never a gap:

php

foreach ($paths as $p) { $out[] = row($p, file_exists($p)); }

  1. The detector that detected nothing

Then I extracted a cache-key drift scanner (finds pages serving assets under old ?v= keys after page-local bump passes). Its very first test run reported "no drift" on a fixture with drift deliberately planted in it.

The bug: I read the version key after stripping the query string off the URL.

php

$url = strtok($url, '?'); // strip the query

$ver = $matches[1] ?? ''; // ...then look for ?v= in what's left

Every reference parsed as versionless. No asset had two versions. "No drift," everywhere, forever. And php -l passed it, because it's perfectly valid PHP that computes a perfectly wrong answer.

This is the scary category. Bugs 1 and 2 fail loudly once you look. Bug 3 fails green: the tool's entire job is to say "clean" or "dirty," and it said "clean" with total confidence. A detector that detects nothing doesn't look broken. It looks finished.

One-line fix - capture the version before stripping - and the fixture immediately reported the planted drift. But the lesson isn't the line.

The actual rule

None of this means stop running php -l. It catches real things and it's free.

The rule is what php -l is for: it answers "does this parse?" Nothing else. Every process that treats a clean parse as a rehearsal - "it linted, so it works" - is betting that semantics live in syntax. They don't. They live in the data, the order of operations, and the return values, none of which the linter sees.

So: lint, then run the real file against real bytes. Not a mock. Not a dry read. The actual served input, the actual output format, checked against what you expected - with an explicit assertion for the failure case, so silence can't impersonate health.

Two of my three were caught exactly that way - in rehearsal, before the server ever saw them. The third is the reason the rehearsal exists.

Full write-up on my site: bryanhamilton.info/writing/php-l-passed-my-bug-as-a-feature/ - and the scanner from bug 3 is open source: github.com/bryanhamiltondev/stale-asset-audit

Want more #webdev & #testing deep dives?

Join 5,962+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

Part 2 of 3 in Live-Verified

More Posts

Your AI Doesn't Just Write Tests. It Runs Them Too.

Kevin Martinez - May 12

Dozens of email accounts: learning AI coding tools as a student

rahuldk1105 - Oct 27

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19

Cloudflare Blocked My Server, So I Made My Visitors' Browsers Do the Fetching

bryanhamiltondevverified - Nov 15

Local-First: The Browser as the Vault

Pocket Portfolio - Apr 20
chevron_left
2.6k Points • 43 Badges
Rochelle Park, New Jersey, US • bryanhamilton.info
20Posts
19Comments
20Connections
Full-stack web engineer · PHP & vanilla JS · 25+ years · Founder of The DJ Calendar · Open to work

Related Jobs

Commenters (This Week)

10 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!