What Is Lint in PHP? How Is It Different From PHPStan?

When working on a PHP application—especially an MVC project—you’ll often hear terms like lint, PHPStan, static analysis, and code quality tools. They’re sometimes used interchangeably, but they are not the same thing.

We have a blog post on PHPStan, check before this post to get more idea.

This post explains what lint is, what PHPStan is, and how they differ, in simple terms.

What Is Lint in PHP?

In PHP, lint refers to the built-in syntax checker provided by PHP itself.

You run it using:

php -l file.php

What PHP lint does

  • Checks syntax only
  • Verifies that the PHP code can be parsed
  • Catches basic errors like:
    • Missing semicolons
    • Unclosed brackets
    • Invalid PHP syntax

Example:

echo "Hello"

Lint result:

Parse error: syntax error, unexpected end of file

What lint does not do

  • ❌ No type checking
  • ❌ No logic validation
  • ❌ No understanding of MVC structure
  • ❌ No detection of unused variables or wrong method calls

In short, lint answers one question:

“Is this valid PHP syntax?”


What Is PHPStan?

PHPStan is a static analysis tool that goes far beyond syntax checking. It analyzes your code without running it, but it understands types, logic, and contracts between classes and functions.

PHPStan is installed via Composer:

composer require --dev phpstan/phpstan

What PHPStan does

  • Detects type errors
  • Finds undefined variables
  • Checks method and property existence
  • Verifies return types
  • Identifies dead or unreachable code
  • Helps enforce correct interactions between MVC layers

Example:

function getUser(): User {
    return null;
}

PHPStan error:

Method getUser() should return User but returns null.

This code is syntactically valid, so lint passes—but PHPStan correctly flags it as a bug.


Key Differences Between Lint and PHPStan

FeaturePHP Lint (php -l)PHPStan
Built into PHP
Composer package
Syntax checking
Type checking
Logic analysis
MVC awareness
Configurable strictness✅ (levels 0–10)

How They Work Together

Lint and PHPStan are not competitors—they solve different problems.

A typical PHP MVC workflow looks like this:

  1. Lint – quick syntax validation
  2. PHPStan – deep static analysis
  3. Unit tests – runtime behavior verification

Example CI pipeline:

php -l src/
vendor/bin/phpstan analyse
vendor/bin/phpunit

Why Not Skip Lint?

Lint is:

  • Extremely fast
  • Requires no setup
  • Great for catching silly mistakes early

PHPStan is powerful, but it still assumes your code is valid PHP. Lint ensures that baseline.


Final Takeaway

  • Lint checks if your PHP code is syntactically valid
  • PHPStan checks if your PHP code is logically correct
  • You should use both, especially in MVC projects

If lint asks “Can PHP read this?”,
PHPStan asks “Should PHP trust this?”