Custom PHP

The PHP Code Review Checklist I Use on Small Teams

A PHP code review checklist for small teams is a short, repeated set of checks that catches correctness bugs, security holes, expensive queries, swallowed errors and unclear code before merge. I keep it to five passes — correctness, security, query cost, error handling and readability — because a checklist long enough to satisfy every edge case is one nobody runs on a Friday deploy.

By Saif Al Jahanwebdev-saif.com

Why a short checklist beats a long style guide

A PHP code review checklist works only if a reviewer can finish it in one sitting. A fifty-item style manual gets skimmed, ignored, or argued about; five short passes get run. I wrote this one for small teams where the same two or three developers review every pull request and nobody has a dedicated security or database specialist on call. The order matters: correctness first, then security, then query cost, then error handling, then readability. Reviewing formatting before logic wastes attention on the cheapest problem. Each pass below ends with a handful of concrete checks rather than principles, so a reviewer can tick them off without interpreting policy.

  • Five passes, ordered by impact rather than by convenience
  • A fixed list small enough to finish in one sitting
  • Concrete checks instead of principles that need interpretation
  • The same list applied to every pull request, including small ones

Pass 1: correctness before style

Start with whether the code does what the request says. I read the function signature before the body: strict_types declared, parameter and return types present, and nullable values handled explicitly. Then I trace one happy path and two failure paths by hand, looking for off-by-one loops, uninitialised variables, and array keys assumed to exist. Boundary checks matter more than internal elegance — an empty result, a zero ID, a string longer than the column allows. If the change touches money, dates or permissions, I insist on a test that fails on the old code and passes on the new one.

  • declare(strict_types=1) at the top of every new file
  • Parameter and return types on all new functions and methods
  • Explicit handling of empty results, null values and missing array keys
  • One regression test that fails before the fix and passes after it
  • Date, currency and permission boundaries covered by tests

Pass 2: security at the trust boundary

Security review is mostly a review of trust boundaries. I ask where data enters the application — request parameters, uploaded files, cookies, webhook payloads, environment variables — and check that each one is validated before use. Database calls must use prepared statements with bound parameters; string-concatenated SQL is a hard stop in my reviews. Output is escaped at the point of rendering with htmlspecialchars, passwords are stored through password_hash and verified with password_verify, and file uploads are checked against an allow-list of MIME types and extensions. I also confirm display_errors is off in production and that error logs never land in a public directory.

  • Prepared statements with bound parameters, never concatenated SQL input
  • Allow-listed file types and sizes for every upload path
  • CSRF tokens on state-changing POST requests
  • password_hash and password_verify for all credentials
  • display_errors off and no stack traces in HTTP responses

Pass 3: query cost and the N+1 trap

Slow pages are usually slow queries, and the most common cause is the N+1 pattern: one query to fetch a list, then one query per row for related data. I look for database calls inside loops first, because that cost grows with the dataset rather than staying flat. Next I check that WHERE and ORDER BY columns are indexed, that SELECT lists name columns instead of using SELECT *, and that pagination uses a keyset or a bounded LIMIT rather than loading everything. When a query is hard to judge, I run EXPLAIN against production-like data and read rows examined, not just the timing on my own machine.

  • No database calls inside loops; eager-load relations in one query
  • Indexes on columns used in WHERE, JOIN and ORDER BY
  • Explicit SELECT lists instead of SELECT *
  • EXPLAIN checked on production-sized data for new or changed queries
  • Bounded pagination with a maximum page size

Pass 4: error handling that does not hide failures

Silent failures are harder to debug than loud ones. I review error handling by asking what the caller sees when the database is down, an API times out, or a validation rule fails. Returning false and hoping the caller checks is not a strategy. Exceptions should be caught at the boundary that can decide what to do — retry, show a message, or roll back — not swallowed mid-stack. Every log entry should carry context: request ID, user ID where appropriate, and the failing value, without passwords or tokens. I also check that database transactions have a matching rollback path.

  • Exceptions caught only where a real recovery decision exists
  • Logs with request context and no secrets or card data
  • Transactions with a tested rollback on failure
  • User-facing messages that state the problem and the next step
  • No empty catch blocks that discard the original exception

Pass 5: readability for the next reviewer

Readability is the cheapest performance gain a team can make, because it reduces the time the next person spends reconstructing intent. I check that names describe what a variable holds and a function does, that functions stay short enough to read on one screen, and that early returns keep nesting shallow. Comments should explain why a workaround exists, not restate the code. In WordPress and PHP builds I also look for business logic leaking into templates, and for repeated blocks that deserve one named function. Formatting itself I leave to PHP-CS-Fixer so review time goes to behaviour, not whitespace.

  • Names that state the value or action, without codes needing decoding
  • Functions short enough to read without scrolling
  • Early returns instead of deeply nested conditionals
  • Comments that explain why, never what
  • Formatter and linter run automatically before review

Making the checklist stick on a small team

I am Saif Al Jahan, a WordPress and PHP developer based in Mymensingh, Bangladesh (GMT+6), and I keep this checklist in the repository as a short REVIEW.md so it travels with the code. On small teams the review habit matters more than the wording: a fixed fifteen-minute window, two reviewers rotating, and an agreement that a blocking comment gets resolved before merge. I wire the boring checks — formatter, linter, static analysis, tests — into CI so human attention stays on correctness and security. Review the checklist itself every quarter: delete a check nobody acts on, and add one only after a real bug slipped through.

  • Keep the checklist in the repository as REVIEW.md
  • A fixed review window with a two-person rotation
  • Formatter, linter, static analysis and tests in CI
  • Blocking comments resolved before merge, not deferred
  • Quarterly pruning: remove checks that never catch anything

Frequently asked questions

What should a PHP code review checklist include for a small team?

Five passes, in this order: correctness, security, query cost, error handling and readability. Correctness asks whether the code does what was requested and handles boundary values. Security checks trust boundaries, prepared statements, escaping and credential storage. Query cost looks for N+1 patterns, indexes and bounded pagination. Error handling checks that failures are logged with context and surfaced clearly. Readability protects the next reviewer.

How long should a code review take?

For a normal pull request I budget fifteen to twenty-five minutes. That is enough for one careful pass through the diff, a look at the changed tests, and a check of the database calls. If a review regularly takes an hour, the change is too large or the checklist is too long. Split the pull request rather than rushing the review.

Which PHP security checks are non-negotiable?

Prepared statements with bound parameters for every query built from user input, output escaped at render time, passwords stored with password_hash, uploads validated against an allow-list, and CSRF tokens on state-changing requests. I also require display_errors to be off in production. A review that finds concatenated SQL or a plaintext password stops there, however clean the rest of the change is.

How do I catch N+1 queries during review?

Search the diff for database calls inside loops, then check whether related records are loaded in one query instead. Watch for ORM lazy loading hidden behind property access. For any new or changed query, run EXPLAIN on production-sized data and check rows examined, not just local timing. Adding a query-count assertion in tests makes the regression visible before it reaches production.

Do I need a tool to run this checklist?

No. The checklist is a habit, not a product. Tools handle the mechanical parts: PHP-CS-Fixer for formatting, PHPStan or Psalm for static analysis, and PHPUnit for tests. I put those in CI so reviewers spend their time on correctness, security and query cost. The human checks are the ones that need judgement about intent and trade-offs.

Does this checklist change for WordPress or WooCommerce projects?

The five passes stay the same, but I add a few WordPress checks: capability checks before privileged actions, nonce verification on form handlers, prepared statements through $wpdb->prepare, and no business logic inside template files. For WooCommerce I also check that price and stock changes run on the right hooks and that payment callbacks are verified before order status is updated.

Written by Saif Al Jahan, webdev-saif.com · Mymensingh, Bangladesh. Last updated .